Login Page In PHP With Database Source Code
Last Updated : Mar 11, 2024
In this tutorial we will show you the solution of login page in PHP with database source code, today we are going to understand how to create a login page in php with database source code.
In previous tutorial, we have done how to create a registration page in php with database.
Step By Step Guide On Login Page In PHP With Database Source Code :-
Here, as given below we create a page named login. Php and inside that page we use database, jQuery, some html also.
One thing to note here that we link a file that is if CSS, which we did not provide in this example, don’t worry about that its only for designing purpose. Now, let see the codes.
// login.php <?php session_start(); $connect=mysqli_connect("localhost","root","","index") or die("Connection Failed"); if(!empty($_POST['button'])) { $name=$_POST['username']; $email=$_POST['email']; $pass=$_POST['password']; if($email== "" && $pass == "" && $name=="") { echo "<script> alert('Please fill all fields.......')</script>"; } else { $query= "select * from rl_form where email='$email' and pass='$pass' and user='$name'"; $result=mysqli_query($connect, $query); $count= mysqli_num_rows($result); if($count>0) { setcookie("username",$name); header("location:welcome.php"); // echo "<script> alert('Congratulations! you are logged in .......')</script>"; } else { echo "<script> alert('Username/Email and Password does not match.......')</script>"; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>home page</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="main"> <div class="inner"> <div class="welcome"> Login Form </div> <div class="login_options"> <form action="" method="post"> <div class="lleft_body"> <label for=""> Enter your username here </label> <br> <label for=""> Enter your email here </label> <br> <label for=""> Enter your password here </label> </div> <div class="lright_body"> <input type="text" name="username" id=""> <br><br> <input type="email" name="email" id=""> <br><br> <input type="password" name="password" id=""> </div> <div class="login_submit"> <input type="submit" value="Login" id="login" name="button"> </div> </form> </div> </div> </div> </body> </html>
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
- Here, as we can see that we create a login page in php. First of all the database which we use in this article is index and inside that our table name is rl_form.
- After that in body you will see we create three inputs first for name, next for email and last for password. This all data is going to check through database.
- And we use some jQuery codes also here. We hope that you understand this article properly.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.
Conclusion :-
At last in conclusion, here we can say that with the help of this article we are able to understand how to create a login page in php with database source code.
I hope this tutorial on login page in PHP with database source code helps you and the steps and method mentioned above are easy to follow and implement.