article

Friday, June 8, 2018

Simple PHP MySQLi Login Form

Simple PHP MySQLi Login Form
//login.php
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<title>Simple PHP MySQLi Login Form</title>
</head>
<body>
 <form method='post' action='validate_login.php' >
  <table border='1' >
   <tr>
    <td><label for='username'>User Name</label></td>
    <td><input type='text' name='username' id='username'></td>
   </tr>
   <tr>
    <td><label for='users_pass'>Password</label></td>
    <td><input name='users_pass' type='password' id='users_pass'></input></td>
   </tr>
   <tr>
    <td><input type='submit' value='Submit'/>
    <td><input type='reset' value='Reset'/>
   </tr>
  </table>
 </form>
</body>
</html>
<?php
$conn = new mysqli('localhost','root','','testingdb');
if ($conn->connect_error) {
    die('Error : ('. $conn->connect_errno .') '. $conn->connect_error);
}
$username = $_POST['username'];
$pass = $_POST['users_pass'];
$sqlc="SELECT * FROM users WHERE username = '$username' OR password = '$pass'";
if ($rsdc=mysqli_query($conn,$sqlc)){
  $total=mysqli_num_rows($rsdc); 
  if ($total == '1') {
   echo'<h1>You are a validated user.</h1>';
  }else{
 echo'<h1>Sorry, your credentials are not valid, Please try again.</h1>'; 
  } 
}
?>

Related Post