Create a Registration and Login System with PHP and MySQL

How To Create a Registration and Login System with PHP and MySQL

Registration and Login System with PHP and MySQL.


You’re assigned to create a Registration and Login System with PHP and MySQL, but you don’t know how to do it? Here’s your guide on How to Create a Registration and Login System with PHP and MySQL. 

Today, almost all website have registration and login functionality. So you just have to add it to your website and other applications as well.

This How-To article will teach you how to create a registration system. The process is simple, users will provide a username, password, and email. Once the account is fully registered, the user can log in to their account. 

A new window will pop up, the user Dashboard page. Also, they can log out from it. This system is developed using PHP and MySQL. 

In this article, we’ll show you how to build one in which only registered users can log in. 

Let’s proceed to the First step.

Creating Database and Database Table

Log in to PHPMyAdmin. Select the Database tab to create a new database. Key in your database name, and then click create. PHPMyAdmin will create a new database. 

Alternatively, you can execute the codes below to create a database. 

CREATE DATABASE LoginSystem;

After creating the database, we’ll create a user table with the following fields.

  • Id – int(11)
  • Username – varchar (100)
  • Email – carchar(100)
  • Password – varchar (100)
  • Create_datetime – datetime

Here’s the code.

Copy it and paste into the SQL query area. 

If perfectly executed, your table will look like this.

Connecting to the Database

After the table has been created, we’ll create a script connecting a PHP MySQL to the MySQL database server. In this tutorial, we will name the file with db.php and write the following codes inside it. 

Creating Session for Logged in User

Copy the codes below and paste in the auth_session file. It will be saved as auth_session.php.

Create a Registration Form

Moreover, create the PHP file registration.php. It will have the following codes in it. This allows you to create an HTML form, allowing users to register.

Perfect codes’ execution will result in the same window below. 

Create a Login Form

Same as above, create a PHP file login.php and put the following examples in it. It contains a form that allows the user to enter a username and password.

The output will look like this. 

Creating a Welcome and Dashboard Page. 

Once there is successful user creation and successful login, it will redirect to the user dashboard page. Create a PHP file named dashboard.php, copy and paste the codes below.

Perfect code will look like this.


Related


Destroy Session – Creating Logout 

If the user decides to end his session, he probably wants to log out. This process will redirect the user to the login page.

Adding Design – Creating a CSS File

Your system won’t be complete without a CSS. Create style.css and write the codes below in it.

Conclusion

Here’s the complete code if didn’t able follow the process.

This is the process lets you create a registration and login system. We hope the it answered your question “How to Create a Regsitration and Login System”.

Recapping the flow.

  1. Create a Database and Database Table
  2. Connect to the Database
  3. Session Create for Logged in User
  4. Create a Registration and Login Form
  5. Make a Dashboard Page
  6. Create a Logout
  7. Create CSS File

Let us know your questions and feedback in the comment box below. Save this later or bookmark it on your browser for faster search.


Complete Registration and Login System with PHP and MySQL

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts