Registration page using PHP

This tutorial is for PHP beginner who want to code a simple registration page for their website or any PHP web application. To create a working registration form you need a database in which you will store data that will be entered in registration form. We have taken necessary precaution in our codes in order to prevent it from intruders and hackers. Its a secure registration page that you can use in your projects doing necessary modification as per your need.

In this example my database name is ‘CLASS’ and it has a table with name ‘STUDENT’. The structure of student table is as follows:

CLASS table has three columns with name ‘ID’,’NAME’ and ‘PASSWORD’. SQL command to create CLASS table is:

CREATE TABLE IF NOT EXISTS <code>class</code> (
<code>id</code> int(2) NOT NULL AUTO_INCREMENT,
<code>name</code> varchar(20) NOT NULL,
<code>password</code> varchar(50) NOT NULL,
PRIMARY KEY (<code>id</code>)

Now we have to code a registration form and registration.php script.Registration form can be created using html or you can code the form within registration.php. We’ll use the first method to write our code.

Code for Registration.html:

<form action="registration.php" method="post">
<label>Name :</label>
<input type="text" name="name"/><br />
<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Submit "/><br />

Code for registration.php:

&lt;?php $connection = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;12345&quot;)
or die(&quot;Opps some thing went wrong&quot;);
or die(&quot;Opps some thing went wrong&quot;);

$name = strip_tags(substr($_POST['name'],0, 100));
$safename = mysql_escape_string($name);
$password = strip_tags(substr($_POST['password'],0, 100));
$safepassword = mysql_escape_string($password);
/* Securing registration page from SQL injection and XSS */

$encrypted = md5($safepassword);

// Encrypting Password Using md5 algo
$query=mysql_query(&quot;INSERT INTO class(<code>name</code>,<code>password</code>)
VALUES('$safename','$encrypted')&quot;); ?&gt;

If you have any doubt regarding registration script in PHP then please feel free to ask. Share the tutorial to help beginners to learn. Also comment how you can make this code more secure and reliable.

About sanjeev

Dreamer, Blogger and Thinker. I love to help people in solving their problems. You can also join me HERE

Related posts:

27 Responses so far.

    1. Hi Vikku,
      It’s great that you want to learn PHP. Follow our tutorials to create your web projects easily. For basic PHP syntax and functions please refer

  1. hello,

    iam using wamp server.i created one database as apple and table name is given by users.

    and created one registration form.using…..and validation form.but i got errors.iam newly about this php.

    so please provide the complete registration form and validation form with database connectivity as soon as possible……..or mail me.

  2. hi i have a registration with a table with first name last name habbo name username password confirm password email and confirm email. how do i make it so the database works for the habboname and username, but stores all the data in a database or file. and how do i set up a database as well.

  3. It gives me an error saying that, mysql_connect():Access denied for user ‘root’@’localhost’. Please tell me what’s the problem.

    1. Hi marcus,

      Make sure that you have set password “12345” for root user. If you have left it to no password for root user then in “registration.php” dont pass any password. Please let me know if it fixes up your issue.


      1. Hi Sanjeev

        I didn’t set the password for the root & its working properly but now the problem I’m facing is that it doesn’t save the data to the server.

      2. in the ‘root’ and password ‘12345’ are those username and password are created in the privileges tab? cause thats my problem as well

  4. Hey guys I need help here I’m working a form that has multiple checkboxes so I need to store them on a database. Please help me out! Do an example that has a username, surname and checkboxes using arrays on checkboxes.

  5. I want to know how do you retrieve or get information on mysql whenever you’ve uploaded it on your webpage. I’ve done it and it worked properly but now I want to retrieve those thing e.g pictures, word document & videos.

Leave a Reply

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