W7Code » PHP » How create a login form using PHP

Today we will learn how to build a login form using PHP and MySQL. Nowadays the safety of the information of the users is so important such as their lives. For that reason it is import keep them in a safe environment. So lets start!

 

For create a login form we need have a database to check if an user exists, so we need create one. For that we will use SQL and MySQL to create a database named ‘ login_form ‘ using:

 

Then we open the database and create a table called users:

create a login form data base

 

Now we have created a database we need to establish a connection with it, for that we will create a file named ‘ bd.php ‘. And put their this code:

 

Next we will create our login form that request the username and password to the user. For this will create a new file named  ‘ login.php ‘:

 

In the beginning of the code we use <?php include(‘connection.php’) ?>, to call a file named ‘connection.php‘, with contain our login settings when the user press the login button. So we need create a new file named ‘connection.php‘:

 

It is almost done, now we just need create a user panel. If the username exists, the user will be redirected to user panel. So we need create one! We will create a file named ‘ user_panel.php ‘:

 

Some Code Explanation

To unset the session and logout the user we user the following php code:

This get from url the value of ‘logout’, using method GET.

 

Now we just need some style to our form, for that we will create a new file named ‘ style.css ‘, with will contain all of our styling option for our form.

 

Our final result:

login php

user panel php

 

If you want try if login form works, create a user in MySQL, using:

 

And enter with the credentials:

Username: admin

Password: 12345

 

Learn Now “How to Create a Registration Form in PHP“!

 

In the next class we will learn how to create a register form using php.

If you have any doubt please comment bellow!

 

2 Comments

  1. Smithd805 says:

    Hi! This is my first visit to your blog! We are a fdekbcfacdcdbdkd

  2. Agen Judi Casino SBOBET Terpercaya says:

    Everything is very open with a very clear clarification of the issues.
    It was really informative. Your site is extremely helpful.
    Thank you for sharing!

Leave a Reply