LOGIN FORM VERIFICATION USING DATABASE
Step:1 Create login page(login.html) in \xampp\htdocs folderusing the following HTML code
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<style>
h1,div
{
text-align:center;
}
</style>
</head>
<body>
<h1>Login</h1>
<div>
<form name="myform" action="dbselect.php" method="post">
User Name:<input type="text" name="uname"><br><br>
Password:<input type="password" name="pass"><br><br>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>
Step:2 Create a following PHP file(dbselect.php) to verify username and password using database data
<?php
$uname=$_POST['uname'];
$pass=$_POST['pass'];
$status=0;
// Create connection
$conn = new mysqli("localhost", "siva", "123", "test");
// Check connection
if ($conn->connect_error)
{
die("Connection failed:" . $conn->connect_error);
}
$sql = "SELECT * FROM login";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
if(!strcmp($row["username"],$uname)&&!strcmp($row["password"],$pass))
{
$status=1;
break;
}
}
}
else
{
echo "No Records Found";
}
if($status==1)
{
// 301 Moved Permanently
header("Location: http://localhost/welcome.php", true, 301);
exit();
}
//echo "Login Succes";
else
echo "Login Failed";
$conn->close();
?>
Step:3 Save this file with name dbselect.php or any other name with .php extension in the same folder (\xampp\htdocs\). Ensure this filename and filename given action attribute of the login form is same.
<form name="myform" action="dbselect.php" method="post">
Step:4 Run login.html file as follows from your web browser
http://localhost/login.html
Step:5 Type username and password available in the database. The login records available in the database as follows
Step:6 Now you will see the following page
THANK YOU