In this tutorial, I’m going to show how to create a login page in PHP, creating a login page for beginner is a big problem. I’m trying to keep this easy so you can understand this and create your PHP project awesomely.
Here is the coding for login page in PHP with step by step process below:-
Step 1. First We need to create a HTML page with two textbox input and one “login” button, name it to “login.html”.
<html>
<title>Login Page</title>
<body>
<form method=”POST” action=”chklogin.php”>
Enter Username : <input type=”text” name=”usrname”/><br>
Enter Password : <input type =”password” name=”psw”/><br>
<input type=”submit” value=”Login”/>
</form>
</body>
</html>
Step 2. Now make a php page of name “chklogin.php” that will check the username and password from database and then authenticate the user.
<?php
$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “test”;
//Creating Connection to database
$conn = new mysqli($servername, $username, $password, $dbname);
//Fetching values from url and storing it in PHP variables
$name = $_POST[‘usrname’];
$psw = $_POST[‘psw’];
//Query to check value in database or not
$sql = “SELECT * FROM user WHERE usrname = ‘$name’ AND pas = ‘$psw'”;
$result = mysqli_query($conn, $sql);
$row = mysqli_num_rows($result);
if($row > 0){
//code for successful login
}else{
//code for failure
}
//Closing Connecion with server
$conn->close();
?>
If you have any other idea to create the login page in PHP more responsive using CSS Please share with us and comment below. 🙂
Check out more PHP tutorial by techlifediary