Sunday, May 3, 2020

Create Login Page Using mysqli_real_escape_string In PHP 7



The tutorial talks about using mysqli_real_escape_string in PHP 7. The mysqli_real_escape_string() function escapes special characters in a string for use in an SQL statement. The function is also popular in making connections to mysql database. See also the
picture and link below.
login page in php

<!DOCTYPE html>
<html>
   <head>
    <meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

   <div class="container">
       <h3 class="text-center">Login</h3>
       <?php

$servername = "localhost";
$usernamedb = "root";
$passworddb = "";
$dbname1= "parent";
$mysqli = new mysqli($servername, $usernamedb, $passworddb, $dbname1);
 
     if(isset($_POST['submit']))
{
$username = $mysqli->real_escape_string($_POST['username']);
$password = $mysqli->real_escape_string($_POST['password']);
if($username === 'username1' && $password === 'password1')
{
header('location:barcodev72.php');
}
else
   {
echo "<div class='alert alert-danger'>Username and Password do not match.</div>";
   }
}

    ?>

<form action = "" method="post">
   <div class = "form-group">
     <label for ="username">Username:</label>
<input type="text" class ="form-control" id="username" name="username" required>
</div>
<div class="form-group">
   <label for="pwd">Password:</label>
   <input type="password" class ="form-control" id="pwd" name="password" required>
     </div>
<button type = "submit" name="submit" class="btn btn-default">Login</button>
   </form>
   </div>
   </body>
   </html>

The Partners

Click this YouTube video link for more understanding. 
 

No comments:

Post a Comment