6 Steps to Create Simple User Registration Script in PHP and 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 My Video on User Login, Registration Script in PHP & MySQL

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

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.

Incoming search terms:

  • registration form in php
  • simple registration form in php
  • PHP registration script
  • php registration form
  • php code for registration form
  • user registration form in php
  • php register script
  • php code for registration
  • php signup script
  • php registration form with database connection code
Vivek Vengala

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

Click Here to Leave a Comment Below 26 comments

You there step no 6 file name what ? what can be save that file


IMHO, using mysqli extension is better than mysql ext. but thanks for this good tutorial. 🙂

Elena Calvillo

THANK YOU SO MUCH!, I understand better this subject now =)


I have been reading tons of blogs regarding this, but i was not satisfied. Thanks to the author and thanks to codingcyber:)


Simple and clean php steps here. Thank you so much!

Saurabh Prakash

Your post is just awesome sir
I also tried so much to make a login and registration system

Thanks u so much and your one is just awesome



I don't where to write d above code in d form opening tag. Pls i need some help writing it.

    Vivek Vengala

    Hi Andrade,

    Please put the code in same file above HTML opening tag, or else you can unlock the complete code and save it in a file.

    Let me know, if you still have any problem.


Hi sir,
This is sujata,i want to know what is code of Registration form and how to connect to that with database.plz let me know

    Vivek Vengala

    Hello Sujata,

    You can watch my video series to understand about this.

    If you have any questions let me know…


When I run it it tells me there is an error on line 10



I did everything like you, but i have issue to send data to Mysql in database, when i ran this code

$query = “INSERT INTO ‘login’ (‘username’,’password’,’email’)VALUES(‘$username’,’$password’,’$email’)”;
$result = mysqli_query($connection, $query);
$smsg = “User Created Successfully.”;
echo “success;
$fmsg =”User Registration Failed”;
echo “Error occured”;
I wounder what I am doing wrong?

thank you for sharing this with us


Hi again!

it shows no error, but when I use echo in if/else statement, it shows the else one. Error occurred. I tried different syntax for query part, still does not work

$smsg = “User Created Successfully.”;
echo “success;
$fmsg =”User Registration Failed”;
echo “Error occured”; <— this is occurred.


can i copy the entire register.php and use for entire reg form !!


Vivek Vengala,Thanks a lot, So helpful. Its easy to understand.

Shrabany Roy

where I input the last section ?

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

    Vivek Vengala

    Hi Sharabany,

    You can use this anywhere you want to display the messages. Right place is in div with container class block.



I have followed the steps exacly, but I get ‘User Registration failed’ when trying to register :/

    Vivek Vengala

    Hi Eddie,

    In your SQL query use die & mysqli_error PHP functions. so that you can get the exact error message.


Hi! Good day! I’m encountering some problems. I can’t seem to connect it to my database. Keep on User Registration Failed.

    Vivek Vengala

    Update connect.php file with your database credentials, don’t forget to upload SQL file


Hi I have advanced login system given by you but I don’t know its configuration
so can u tell me this?

    Vivek Vengala

    Hi Mayank,

    After extracting the zip file, you will find SQL file. Import it using PHPMyAdmin and update database configuration options.


Leave a Reply: