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 `class` (
`id` int(2) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`password` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
);

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 />
</form>

Code for registration.php:

<?php $connection = mysql_connect("localhost","root","12345")
or die("Opps some thing went wrong");
$db_select=mysql_select_db("school",$connection)
or die("Opps some thing went wrong");

$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("INSERT INTO class(`name`,`password`)
VALUES('$safename','$encrypted')"); ?>

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.

27 thoughts on “Registration page using PHP”

  1. Pingback: Login page using PHP | InfoTuts | Programming | PHP |Jquery |HTML5/CSS3|

  2. Pingback: Captcha Code in PHP. | InfoTuts | Programming | PHP |Jquery |HTML5/CSS3|

    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 w3schools.com

  3. Pingback: Insert Data in Database using jQuery and PHP | InfoTuts | Programming | PHP |WordPress |HTML5/CSS3

  4. 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.

    1. Hi Srilatha,

      You can use this registration form and use javascript for validation at client end.

  5. Pingback: Create Simple But Secure Registration form in PHP using PDO - InfoTuts

  6. 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.

  7. Can you plz help me to make a registration form which can also add image.I am in a very big problem

  8. 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.

      Regards:
      Sanjeev

      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

  9. 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.

  10. 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.

  11. Hi, i just wanna ask if how i will retrieve a password in php? i mean i want to know on how to get or the user will get their password if they forgot it? 🙂

Comments are closed.