login in PHP using Mysql Tutorial makcode.in


Today i will share Simple Login Script in PHP and MySQLi, i will explain the basic of login . In this tutorial user can login to user database.

In the tutorial we login form user database from MySQL.

In this example we used 2 file for retrieve data

  • database.php– To connecting database.
  • login.php– For getting access from database for login


$dbname = "user_details";
 die('Could not Connect My Sql:' .mysql_error());


if(count($_POST)>0) {
include_once 'database.php';
$result = mysqli_query($conn,"SELECT * FROM user WHERE (userid='" . $_POST["userid"] . "') and password = '". $_POST["password"]."'");
$row = mysqli_fetch_array($result);
if(is_array($row)) {
$_SESSION["userid"] = $row[userid];
} else {
$message = "Invalid Userid or email or Password!";
if(isset($_SESSION["userid"])) {
echo "Success";
<title>User Login</title>
<form method="post" action="" align="center">
<div class="message"><?php if($message!="") { echo $message; } ?></div>
<h3 align="center">Enter Login Details</h3>
Userid or mobile:<br>
<input type="text" name="userid">
<input type="password" name="password">
<input type="submit" name="submit" value="Submit">
<input type="reset">