PHP Login Page Example for Beginners

This post is related to PHP Login module for PHP beginners. Most of the PHP beginners are worried about how to start a small login project using PHP code with MySQL database. So here I go…

Step1: Create Database
Create database 'databasename'

Step2: Create Table
CREATE TABLE `admin` (
`id` int(11) NOT NULL auto_increment,
`userid` varchar(30) default NULL,
`user_password` varchar(30) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `userid` (`userid`)
) ENGINE=MyISAM;

Step3: Create config.php file

Step4: Create Login form page – give name as index.php or login.php




Design3edge

Login Page



Wrong details



 




Step5: Create LoginAction.php file
0 means some result is there else no result
$num=mysql_num_rows($result);
if ($num > 0) {

if($row = mysql_fetch_array($result))
{
$username = $row['userid'];

// You can set session paramater value here
session_start();
$_SESSION['username']=$username;

// If success then calling other page
header("Location: welcome.php");
exit;
}

}
else
{
// If failure then calling same page with error message display
header("Location: index.php?msg=wrong");
}
?>

Final Step: Create welcome.php file

Welcome to ""