How to make Login / Authentication page in php and mysql - 4 Step

Hello Guys In This Post We will Learn about How to make Login / Authentication page in php and mysql, More security to login with help of php and mysql.

How to make Login / Authentication page in php and mysql

To do this process you have wamp server and notepad++ with PHP Version 5.3, Do You want to make Login page in php so you need to follow some step to create login page in php and mysql.

How to make Login / Authentication page in php and mysql

If  You have already download and install Wampserver /  xampp server in your pc then you need to follow only some step to create login page in php.

First Step : Create Table in Mysql

CREATE TABLE IF NOT EXISTS `admin_` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `username_` varchar(50) DEFAULT NULL,
  `password_` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

Second Step : Create Connection in php (Config.php)

<?php

$servername = "localhost";
$username = "sachin";
$password = "abc";
$dbname = "employee_db";

mysql_connect($servername,$username,$password);
mysql_select_db($dbname);

?>

Thired Step : Create Design for Login Page (Login.php)

<form class="login-form" action="" method="post">
   <h2>Admin Login Page</h2>
      <input type="text" name="username" required="required"  placeholder="username"/>
      <input type="password" name="password" required="required" placeholder="password"/>
      <input type="Submit" name="Submit" value="Login" />
            <p class="message">Not registered? <a href="#">Create an account</a></p>
    </form>

Thired Step : Write Code When Login  button Click (Login.php)

<?php 
if(isset($_POST['Submit']))
{
    
if(!$_POST["username"]=='' && !$_POST["password"]=='')
{    
include"Config.php";

$username=$_POST["username"];
$password=$_POST["password"];

// prevent my sql injection

$username=stripcslashes($username);
$password=stripcslashes($password);
$username=mysql_real_escape_string($username);
$password=mysql_real_escape_string($password);

$result=mysql_query("select * from admin_ where username_='$username' and password_='$password'");

$row=mysql_fetch_array($result);

if(($row['username_']==$username) && ($row['password_']==$password ))
{
session_start();
$_SESSION['username']=$username;
 header("location:Success.php"); 
}
else
{
echo"Your Login Name or Password is invalid";
}
}

}
?>

if you have any error then you need goes this link login system in php 5.5