PHP Login Page With Database Connection
In order to create a login page using php and html, several steps must be taken.
Step 1:
First we need to create database_connection.php page
database_connection.php
<?php
$Server_name="localhost";
$Username="root";
$Password="";
$Database="details_db";
$link=mysqli_connect($Server_name,$Username,$Password,$Database);
?>
Step 2:
Make a table called details_db,and create a tale called admin_tbl.
The table has four columns:admin_id,username,password,and created_date(its an optional).
Step 3:
Login_page.html
<html>
<head>
<title>PHP LOGIN PAGE WITH DATABASE CONNECTION<title>
</head>
<body>
<center>ADMIN LOGIN <br><br>
<form action="Login_process.php" method="POST">
Enter Username <input type="text" name="username" ><br><br>
Enter Password <input type="password" name="pass"><br><br>
<input type="submit" value="Login">
</form>
</center>
</body>
</html>
Step 4:
Login_process.php
<?php
include("database_connection.php");
$user_name=$_POST['username'];
$password=$_POST['pass'];
$true_flag=0;
$query="Select * from admin_tbl where username='$user_name' and password='$password'";
$result=$link->query($query);
while ($row=mysqli_fetch_array($result))
{
$true_flag=1;
}
if($true_flag==0)
{
echo "Login Failed";
}else{
echo "Successful";
}
?>
Comments
Post a Comment