6 Easy Steps to Create Simple & Secure PHP Registration Script - Free
  • Home
  • PHP

6 Steps to Create Simple User Registration Script in PHP and MySql

simpe user registration script in php mysql

This is a Simple User Registration Script in PHP and MySQL. By using this user can easily register, filling username, email, password fields. After submitting form, the data will be stored in a database table. So that next time user can login with the login credentials which are used while user registration.

Here these are a series of articles

These scripts are for beginner learners, who want to learn the concept of user registration, login, login activation and forgot password.

  1. Simple User Registration Script in PHP and MySQL
  2. Simple Login Script in PHP and MySQL
  3. User Login with activation check using PHP and MySQL
  4. Send Forgotten Password by mail using PHP and MySQL
  5. Check Username Availability With jQuery In PHP And MySql

Steps to creating Simple User Registration Script in PHP and MySql

  1. Create a database
  2. Creating table with five fields
    • id
    • username
    • email
    • password
    • active
  3. Create form in html
  4. Adding styles to form
  5. Connect to the database using php
  6. Writing logic for user registration script in php

Below is the Video on PHP User Login Registration Script With All Features

1. Create a Database

For creating a database, login to phpmyadmin, then click on Databases tab. And in the input field enter database name and click on create database button.

2. Creating a Database table

After creating Database, Create a database table for users, it’s simple table with user name, email, password, active and an id as primary key and also it is auto incremented.

  • id is the primary key and auto incremented.
  • Username field will be used for storing username
  • email field will be used for storing email address of user, this will be used to send forgotten password by email  in this series.
  • Password field will store password of user in normal format.
  • active state is for checking the user is active or blocked user, If the user is blocked then he can’t login to system.

Import this below sql into your database.

3. Create form in html

Save this file as register.php, Here this is simple html for generating form. This form contains user name field, email, password a submit button and a link to login.php file. Here i’m adding some classes to the HTML, Later i can add some styles.

4. Adding styles to form

Here i’ve added some styles to form, so that it will look good. I’m using Bootstrap with some custom styles.

Put this code in head section of register.php file

Save this code as styles.css file

5. Connect to the database

Create a file with name connect.php. Here i’m connecting to database and selecting the database.

User correct database name & user credentials.

6. Writing logic for user registration script in php

All the registration process done in one single php file, in this file we will display an html form for user to register. In the PHP section we will first connect to the database, then we will select the database, if the values are posted, then we are running a MySQL query it will insert the values into the database.

Add this code register.php file above the html code. That means right before step 3 code. If you have any dobut, you can check the final code.

Add this code after opening form tag, this code is used to display the status message.

Complete Code of Register.php

Download the Complete Code


Download the Complete Code


Next Steps After User Registration

About code is just simple user registration code for educational purpose, if you are implementing this code in the real-world application then you should use these techniques.

Sanitize the Data

First of all, you should sanitize the data. This will helps to stop the sql injection & cross-site scripting XSS attacks. To stop sql injection use mysqli_real_escape_sting PHP function. And for XSS attacks you should use htmlentities PHP function.

Example of the code is below, you should apply this to all the submitted values.

Password Encryption

In the above code, you can see I’m storing passwords in plain text method. That is not recommended method to store passwords in the database. Use password_hash PHP function to store the passwords in database, it’s a secure method to store the password in database.

If you follow these above methods, you can create a secure user registration process for your web application.

If you want to learn other things you can read other posts – registration, login, user login with activation check, and sending forgotten password by email, Check Username Availability .

I hope this article helped you to learn user login using PHP and MySQL . To get latest news and updates follow us on twitter & facebook, subscribe to newsletter. If you have any feedback please let us know by using comment form.

Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.