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.


Posted

in

,

by

Tags:

Comments

27 responses to “Registration page using PHP”

  1. […] my last post I explained how to code a registration page in PHP. Now if you have created your registration.php page successfully then its time to move ahead and […]

  2. […] all web developers and freelancers it’s a useful post because they have to code a registration page for almost all projects . It is always recommended to put some captcha verification mechanism in […]

  3. vikku Avatar
    vikku

    Hi , I ‘m beginer ,
    Please help me to learn PHP
    Thanks

    1. InfoTuts Avatar
      InfoTuts

      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

  4. […] have already posted about inserting any record in database using PHP in my “Registration Page Using PHP” Tutorial. It’s good to insert data using PHP but its better if you add little jQuery in […]

  5. Marc zack Avatar
    Marc zack

    Hi Sanjeev

    You can find a nice sign up form in this site http://www.mcwehbe.com

  6. srilatha Avatar
    srilatha

    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. InfoTuts Avatar
      InfoTuts

      Hi Srilatha,

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

  7. […] a registration page in PHP is not a big deal but making it secure and robust is not easy. Let’s see how we can use PDO for […]

  8. Rifat Avatar

    How can i add more field in a single signup form using jquery and then connect it to the database?

    1. Sanjeev Avatar

      H Rifat,
      Please refer this post Dynamically add input fields and submit to database using jQuery. I hope it will help you.

      Thanks:
      Sanjeev

  9. Shannon Avatar

    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.

  10. Promila Avatar
    Promila

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

    1. Sanjeev Avatar

      Hi Promila,
      You can use this form and to upload images using your form you can see this tutorial https://infotuts.com/improved-php-script-to-upload-images/. Combine these two tutorials and your form will be ready.

  11. marcus Avatar
    marcus

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

    1. sanjeev Avatar

      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. marcus Avatar
        marcus

        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.

        1. sanjeev Avatar

          Hi Marcus,

          Can you show me your code?

      2. Wendell Avatar
        Wendell

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

  12. marcus Avatar
    marcus

    Its working now man thanks.

  13. marcus Avatar
    marcus

    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.

    1. sanjeev Avatar

      Hello Marcus,

      We will surely help you out with your problem and publish a tutorial for the same.

      Regards:
      Sanjeev

      1. marcus Avatar
        marcus

        Okay cool I’ll wait.

      2. marcus Avatar
        marcus

        Please let me know if you’ve posted it

  14. marcus Avatar
    marcus

    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.

    1. sanjeev Avatar

      Hi Marcus,

      You can retrieve all the information from database with “select” query and display it in page using PHP echo. I would suggest you to look at “fetch.php” code in this page https://infotuts.com/fetch-record-from-database-using-jquery-and-php/.

  15. athena Avatar

    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? 🙂