Using MySQL and PHP keep it simple This assignment you will be making a form tha
ID: 3920376 • Letter: U
Question
Using MySQL and PHP keep it simple
This assignment you will be making a form that will do one of three things in a database
- It will add a record
- It will update a record
- It will search for a record
Your database will contain a table for keeping a record of all your friends and family and should contain:
First name
Last name
Phone number
Address
City
State
Zip
Birthdate
Username
Password
The sex of the person
And the relationship
You should also keep a primary key for the user
You will then have two pages a friends and family form page and a results page
The form will ask the user to enter the information and then choose to either
Create a new record
Update and existing record
Search for a record
The results page will display the information that they are requesting with either adding a record, updating it or displaying the results of a record.
Explanation / Answer
rg table:
CREATE TABLE rg(
uid int(11) not null AUTO_INCREMENT PRIMARY KEY,
user_fn varchar(256),
user_ln varchar(256),
user_pn varchar(256),
user_address varchar(256),
user_city varchar(256),
user_state varchar(256),
user_zip varchar(256),
user_bd varchar(256),
user_uid varchar(256),
user_pwd varchar(256),
user_gender varchar(256),
user_relation varchar(256),
);
index.php:
<html>
<frameset rows="7%,*" border=1%>
<frame name="menu" src="menu.php" noresize="noresize">
<frame name="top" src="top.php" noresize="noresize">
</frameset>
</html>
menu.php:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.h{
text-decoration: none;
color: white;
}
table{
width: 400px;
height: 30px;
color:black;
border-collapse: collapse;
}
th{
border-top:0px solid;
}
body{
background-color: black;
}
.r{
text-decoration: none;
color: red;
}
</style>
regist.php:
<html>
<head>
<script type="text/javascript">
funtion fd()
{
var ele=document.getElementsById('nm');
var val=ele.value;
if(val==null)
{
alert("enter your name");
}
}
</script>
<style>
table{
border:1px solid white;
background-color:white;
}
button{
}
.in{
border.radius:2px;
}
body{
background-color:#fdf;
}
.t{
border-style: outset;
border-width: 7px;
border-color: white;
background-color: skyblue;
height: 400px;
}
</style>
</head>
<body>
<h1 align="center">REGISTRATION<h1>
<form action="link.php" method="POST">
<table align="center" class="t">
<tr>
<td>First name: </td>
<td><input type="text" name="fn" value="" class="in" ></td>
</tr>
<tr>
<td>Last name: </td>
<td><input type="text" name="ln" value="" class="in" ></td>
</tr>
<tr>
<td>Phone number: </td>
<td><input type="text" name="pn" value="" class="in" ></td>
</tr>
<tr>
<td>Phone number: </td>
<td><input type="text" name="pn" value="" class="in" ></td>
</tr>
<tr>
<td>Address:</td>
<td>
<textarea rows="3" cols="20" name="address">
</textarea>
</td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city" value="" class="in" ></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="state" value="" class="in" ></td>
</tr>
<tr>
<td>Zip:</td>
<td><input type="text" name="zip" value="" class="in" ></td>
</tr>
<tr>
<td>Birthdate:</td>
<td><input type="date" name="bd" value="" class="in" ></td>
</tr>
<tr>
<td>
Username:
</td>
<td><input type="text" name="uid"></td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="Password" name="pwd">
</td>
</tr>
<tr>
<td>Gender: </td>
<td><input type="radio" name="Gender" value="M">M
<input type="radio" name="Gender" value="F">F
</td>
</tr>
<tr>
<td>Relationship status: </td>
<td><input type="checkbox" name="relation" value="Single">Single
<input type="checkbox" name="relation" value="Married">Married
</td>
</tr>
<tr>
<td><td><button>
</tr>
</table>
</form>
</body>
</html>
home.php:
<!DOCTYPE html>
<html>
<head>
<style>
body{
background-color: #ddd;
}
</style>
</head>
<body>
<?php
include_once 'top.php';
?>
</body>
</html>
top.php:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.tt{
float: right;
border-style: outset;
border-width: 7px;
border-color: white;
background-color: skyblue;
height: 200px;
}
input[type=text], input[type=password] {
width:250px;
padding: 12px 20px;
margin: 4px 3px;
display: outline-block;
border: 1px solid #ccc;
}
body{
margin-top: 50px;
}
.r{
text-decoration: none;
color: red;
}
.b:hover{
color: red;
background-color: blue;
}
h2{
padding:0 0 50 0;
}
.b{
background-color: lightgreen;
width: 200px;
height: 50px;
}
button{
margin-bottom: 20px;
width:100px ;
height:30px ;
}
button:hover{
background-color: #ccc;
}
</style>
</head>
<body bgcolor="silver">
<form action="loginlink.php" method="POST">
<table class="tt">
<tr>
<td>
<h2 align="center">LOGIN</h2>
</td>
</tr>
<tr>
<td>Username: </td></tr>
<tr><td><input type="text" name="uid" placeholder="Enter username"></td></tr>
<tr><td>Password: </td></tr>
<tr><td><input type="password" name="pwd" placeholder="Enter password"></td></tr>
<tr>
<td>
<button>LOGIN </button>
</td>
</tr>
</table>
</form>
</body>
</html>
new.php:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.t{
text-decoration:none;
float: right;
}
</style>
<title>
</title>
<h1>You are logged in successfully</h1>
</head>
<body>
Clicl here to.....
<a href="logout.php" class="t">Logout</a><br>
</body>
</html>
logout.php:
<?php
session_start();
if(session_destroy())
{
header("location:top.php");
}
?>
loginlink.php:
<?php
$servername= "localhost";
$username= "cse";
$password= "cse";
$dbname= "cse";
$conn = mysqli_connect($servername,$username,$password,$dbname);
$uid=$_POST['uid'];
$pwd=$_POST['pwd'];
SESSION_start();
if(empty($uid) && empty($pwd))
{
header("Location:top.php");
}
else
{
$sql="SELECT * FROM rg WHERE (user_username='$uid') And (user_password='$pwd')";
if($res=mysqli_query($conn,$sql))
{
$rowcount=mysqli_num_rows($res);
if($rowcount>=1)
{
$_SESSION['user_username']=$uid;
header("location:new.php");
}
else
{
header("location:fail.php");
}
}
}
?>
link.php:
<?php
$servername= "localhost";
$username= "cse";
$password= "cse";
$dbname= "cse";
$conn = mysqli_connect($servername,$username,$password,$dbname);
$First name= $_POST['fn'];
$Last name= $_POST['ln'];
$Phone number= $_POST['pn'];
$address= $_POST['address'];
$City= $_POST['city'];
$State= $_POST['state'];
$Zip= $_POST['zip'];
$Birthdate= $_POST['bd'];
$username= $_POST['uid'];
$password= $_POST['pwd'];
$gender= $_POST['Gender'];
$Relationship status= $_POST['relation'];
$sql= "INSERT INTO rg(use<style type="text/css">
</style>r_First name,user_Last name,user_Phone number,user_address,user_City,user_State,user_Zip,user_Birthdate,user_username,user_password,user_gender,user_Relationship status)
VALUES('$First name','$Last name','$Phone number','$address','$City','$State','$Zip','$Birthdate','$username','$password','$gender','$Relationship status')";
if(mysqli_query($conn, $sql))
{
echo "Registration Successful";
}
?>
getdata.php:
<?php
include_once 'style.css';
?>
<?php
$servername= "localhost";
$username= "cse";
$password= "cse";
$dbname= "cse";
$conn = mysqli_connect($servername,$username,$password,$dbname);
$sql="SELECT * FROM rg";
$res=mysqli_query($conn,$sql);
echo "<h2>REGISTRATIONS LIST</h2>";
echo "<table> <tr> <th>First name</th> <th>Last name</th> <th>Phone number</th> <th>Address</th> <th>City</th> <th>State</th> <th>Zip</th> <th>Birthdate</th> <th>Username</th> <th>Gender</th> <th>Relationship status</th> </tr> ";
while($row=mysqli_fetch_assoc($res))
{
echo "<tr>";
echo "<td>".$row['user_First name']."</td>";
echo "<td>".$row['user_Last name']."</td>";
echo "<td>".$row['user_Phone number']."</td>";
echo "<td>".$row['user_address']."</td>";
echo "<td>".$row['user_City']."</td>";
echo "<td>".$row['user_State']."</td>";
echo "<td>".$row['user_Zip']."</td>";
echo "<td>".$row['user_Birthdate']."</td>";
echo "<td>".$row['user_username']."</td>";
echo "<td>".$row['user_Relationship status']."</td>";
echo "<td>".$row['user_language']."</td>";
echo "</tr>";
}
echo "</table>";
?>
fail.php:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.g{
text-decoration: none;
}
</style>
<h2>Invalid username or password</h2>
</head>
<body>
To Try Again......<a href="top.php" class="g">Click here</a>
</body>
</html>
style.css:
<html>
<style>
table{
border-color: black;
background-color:skyblue ;
width: 1000px;
border-width: 5px;
}
tr,th{
border-width: 2px;
}
</style>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.