Está en la página 1de 14

PHP FORMS WITH MYSQL

CREATE PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h1 align="center">Register Form</h1>
<form action="create.php" method="post">
<table align="center">
<tr>
<td>Student ID</td>
<td>:</td>
<td><input type="text" name="studentid"/></td>
</tr>

<tr>
<td>Student Name</td>
<td>:</td>
<td><input type="text" name="studentname" /></td>
</tr>

<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password" /></td>

1
</tr>

<tr>
<td>Student Course</td>
<td>:</td>
<td><input type="text" name="studentcourse"/></td>
</tr>

<tr>
<td>Student Department</td>
<td>:</td>
<td><input type="text" name="studentdepartment"/></td>
</tr>

<tr>
<td>Gender</td>
<td>:</td>
<td><input type="text" name="gender"/></td>
</tr>

<tr>
<td></td>
<td></td>
<td>
<input type="submit"/>
</td>
</tr>
</table>
</form>
</body>
</html>

2
CREATE.PHP
<?php
include 'records.php';
$id = $_POST['studentid'];
$name = $_POST['studentname'];
$password = $_POST['password'];
$course = $_POST['studentcourse'];
$department = $_POST['studentdepartment'];
$gender = $_POST['gender'];
$result = mysql_num_rows(mysql_query("SELECT * FROM register2 WHERE name='$name'"));
if($result == 1)
{
echo "Student Name Already Existing";
}
else
{
mysql_query("INSERT INTO register2(id, name, password, course, department, gender)
VALUES ('$id', '$name', '$password', '$course', '$department', '$gender')");
echo "Record Inserted Sucessfully";

}
?>
DELETE.HTML
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="welcom.css" />
</head>

<body background="images/body-bg (2).jpg">

<div class="wrapper">

3
<h1 align="center">Delete Form</h1>
<form action="delete.php" method="post">
<table align="center"><tr>

<td>Student Name</td>
<td>:</td>
<td><input type="text" name="studentname" /></td>
</tr>
</table>

<p align="center"><input type="submit" class="button" value="Delete" /></p>


<p align="right">
</p>
</form>
</div>
</body>
</html>
DELETE.PHP
<?php
include 'records.php';
$name = $_POST['studentname'];
$result =mysql_query("delete FROM register2 WHERE name='$name'");
if($result == 1)
{
echo "Username Deleted Sucessfully";
}
else
{

echo "Record Doesnot Existing";

4
}
?>
UPDATE.PHP
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="welcom.css" />
</head>

<body background="images/body-bg (2).jpg">

<div class="wrapper">

<h1 align="center">Update Form</h1>


<form action="update.php" method="post">
<table align="center"><tr>

<td>Student Name</td>
<td>:</td>
<td><input type="text" name="studentname" /></td>
</tr>

<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password" /></td>
</tr>

</table>

5
<p align="center"><input type="submit" class="button" value="Update" /></p>
<p align="right">
</p>
</form>
</div>
</body>
</html>
UPDATE.PHP
<?php
include 'records.php';
$name = $_POST['studentname'];
$password=$_POST['password'];
$result =mysql_query("update register2 set password='$password' WHERE name='$name'");
if($result == 1)
{
echo "Password Updated Sucessfully";
}
else
{

echo "Record Doesnot Existing";

}
?>
LOGIN.HTML
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="welcom.css" />
</head>

<body background="images/body-bg (2).jpg">

6
<div class="wrapper">

<h1 align="center">Login Form</h1>


<form action="login.php" method="post">
<table align="center"><tr>

<td>Student Name</td>
<td>:</td>
<td><input type="text" name="studentname" /></td>
</tr>

<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password" /></td>
</tr>

</table>

<p align="center"><input type="submit" class="button" value="Login" /></p>


<p align="right">
</p>
</form>
</div>
</body>
</html>
LOGIN.PHP

7
<?php
include 'records.php';
$name = $_POST['studentname'];
$password = $_POST['password'];
$result = mysql_num_rows(mysql_query("SELECT * FROM register2 WHERE name='$name' and
password='$password'"));
if($result == 1)
{
echo "Login Sucessfully";
header('location:welcome.html');
}
else
{

echo "Login Failed";

}
?>
CONNECT.PHP
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("form", $con);
?>
REGISTER.HTML
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="welcom.css" />
</head>

<body background="images/body-bg (2).jpg">

<div class="wrapper">

8
<h1 align="center">Register</h1>
<form action="register.php" method="post">
<table align="center"><tr>

<td width="81">Username:</td>
<td width="247"><input name="username" size="30" autocomplete="off" value="" type="text"
/></td>

</tr><tr>

<td>Password:</td>
<td><input name="password" size="30" type="password" /></td>

</tr>

<tr>

<td>First Name:</td>
<td><input name="firstname" size="30" type="text" /></td>

</tr>

<tr>

<td>Last Name:</td>
<td><input name="lastname" size="30" type="text" /></td>

</tr>

<tr>

9
<td>Age:</td>
<td><input name="age" size="30" maxlength="2" /></td>

</tr>
</table>

<p align="center"><input type="submit" class="button" value="Register" /></p>


<p align="right">
<a href="home.html">Back</a>
</p>
</form>
</div>
</body>
</html>
REGISTER.PHP
<?php
include 'mobilestore.php';
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$result = mysql_num_rows(mysql_query("SELECT * FROM register WHERE
username='$username'"));
if($result == 1)
{
echo "Username Already Existing";
}
else
{

10
mysql_query("INSERT INTO register(username, password, firstname, lastname, age)
VALUES ('$username', '$password', '$firstname', '$lastname', '$age')");
echo "Record Inserted Sucessfully";

}
?>
SCREEN SHOT

11
12
13
14

También podría gustarte