PHP Scripts – WordPress Tutorials


Registration Form PHP Script

This tutorial (Registration Form PHP Script) will let you know “How to create Registration Form Using PHP”. This is Step by step tutorial to create a registration form/Sign Up Form. I have created three major files named as:

  • registration_form.php
  • registration_script.php
  • success_register.php

But before, Sitting in a corner and start development, its important to idealize what you actually have to do. So i will recommend you to first idealize and then sketch that on paper and after the design is ready, start punching PHP. In this tutorial i have used the following design:

Firstly, Create a table into you database, table can keep the records specific fields easily. I have used the following Query to create a table and assign a primary key and make that Auto Increment so that it should keep on registering.

After the table is created, next task is to create a Registration Form in HTML. Your form should look like the following, You can add more fields in form, My form is short because i want to make you understand easily.

 

registration_form.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<html>
<head>
<title>Registration Form</title>
</head>

<body>
<table width="200" border="0" align="center">
<form id="form1" name="form1" method="post" action="registration_script.php">
<tr>
<td colspan="2"><h2 style="color:#FF000">Registration Form</h2></td>
</tr>
<tr>
<td>UserName:</td>
<td>
<input type="text" name="txtUser" id="txtUser" />

</td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="txtPassword" id="txtPassword" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btnRegister" id="btnRegister" value="Register" />

</td>
</tr>
</form>
</table>
</body>
</html>

You have to take care of the name and id of the fields you are using, like i have done for my input fields.

Create another file and paste the following script into it.

registration_script.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//=============Configuring Server and Database=======
$host        =    'localhost';
$user        =    'root';
$password    =    'vertrigo';
$database    =    'dbsneaker';

$conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct');
mysql_select_db($database,$conn) or die('Database Information is not correct');

//===============End Server Configuration============

//=============Starting Registration Script==========

$userName    =    mysql_real_escape_string($_POST['txtUser']);

$password    =    mysql_real_escape_string($_POST['txtPassword']);
$password    =    md5($password);  //===Encrypt Password

if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register

{
$query    =    "insert into tbladmin(admin_usr_name,admin_pwd)values('$userName','$password')";
$res    =    mysql_query($query);
header('location:success_register.php');//Redirect To Success Page
}

I have used function md5(), it is used to encrypt the password. Like if i have inserted 12345 as my password then it will insert some encrypted data into the data base.

You are done! Just for your satisfaction, you can create another file to show a Success message. Here i have also show to insert a link with that to move to the Login Page. here i have tutorial to create a Login Page.

success_register.php

1
2
3
4
5
<body>

<h1> Congrats! you have Successfully Register</h1>
<a href="#"> Login</a>
</body>

If you still have any confusion then don’t forget to ask me. Comment here or mail me. I will respond to your emails frequently.

Random Posts


Categories: PHP, Web Development
  • Madiha Akram

    great ……….

  • http://www.horsereality.com MiszD

    I love this! I finally got my registration form done now.
    With my own code it kept saying that the registration was done. But it didn’t save anything in de database. And now finally the data IS added to the database :D!

    Thank you very much! It really helped me <3

    • http://www.computersneaker.com Mudasir Nazir

      There might be some kind of error with your database connection. I think you have resolved your code with my Comments that i have used and always keep them my main focus while Developing.

      • http://tibetkailashtourpackage.com Gyalgin Sherpa

        I have not idea how 2nd part works, integrating with SQL Server? create page with registration_script.php and then what would be the next step?
        please help…

        • http://www.computersneaker.com/ Mudasir Nazir

          just call this in your browser and you are done for testing.

          • Ayodeji Akinkuolie

            hey..pls i need a code that will work as a register for registering letters coming into a office…use any language.thnks

  • http://testing muhammad israr

    i like ur method bcose it is so simple for a new users

  • Richa Saxena

    Hi,
    This is very simple and easy method for new users,I have one question how can I generate automatic id with the message “Congrats! you have Successfully Register”. like “Congrats! you have Successfully Register and your user ID is abc123″
    thanks in advance…

    • http://www.computersneaker.com/ Mudasir Nazir

      Yes a very nice question from you dear. I really appreciate that you have raised a question. Now the answer is that take this id from you registered user, and at the end of this script, Add the mailing script and send the same email id to that mailing address. It will automatically send a message to your user. For an example you need to study my tutorial PHP Email Script

  • http://scienceinhand.com irfan korai

    oh really we can manage our self a good one registration form…Can we integrate in in wordpress ????

    • http://www.computersneaker.com/ Mudasir Nazir

      Yes you can integrate it with wordpress. Soon i will release new tutorial that will guide you through wordpress registration forms.

  • fahad

    Assalamoalaikum!

    Dear Mudasir,

    Please resolve this error.

    Notice: Undefined index: user in C:\wamp\www\test\signup.php on line 3

    • http://www.computersneaker.com/ Mudasir Nazir

      Actually you have not placed any file with that name there. So you just need to place the right file address.

  • kaycee

    how can I implement php to database? sorry i’m just a beginner.

    • http://www.computersneaker.com/ Mudasir Nazir

      You can do it easily, just read out my SQL statement section.

  • Sahoong

    Hello Mudasir,

    I need help with my php form registration. I want user to be able to review their details before it is finally submitted to the database. After filling all their information, I want user to be presented with all the information that they have supplied and if they are satisfied that the details are correct, then submit the form but if not, return to the form to correct their errors. Please, note that I am not referring to form validation but this is a kind of form summarisation just before submitting the form.

    Your help will be highly appreciated.

    Best regards,
    Sahoong

    • http://www.computersneaker.com/ Mudasir Nazir

      Its Quite simple my dear, you just need to redirect the user to a new page(as i have redirected to the Success.php). and at that page you have to show all that information that a user have sent, Ask the user to confirm that whether he/she wanted to proceed or not? if The answer is true then run the Submit Query session otherwise redirect to edit that page.
      When you are displaying the information you will have to only echo that variables like < ?=$myName;?>
      I hope this will work for your, If you have any query feel free to write.

      • Sahoong

        Thanks so much Mudasir,

        Unfortuntely, I do not know how to do that. The reason being that my form is presently a 1 page form but its very long and at the end of it is the submit button. If I redirect them to another page to see the data that they entered, the posted value from the form must have been lost. From your response, I guess that I need to use session to hold the data but I have tried that before. The problem that I have with users going from one page to the next is returning to the previous page if they think they have made errors. Also, I didn’t quite get the session storage very well. I can redirect the user for sure but assuming that all the information that they have entered are correct, getting them back to the point where they were before they were directed to another page is what I do not know how to do.

        Once again, thanks for your prompt response.

        Regards,
        Sahoong

  • biva

    hey ican’t connect my php form with my database..i m new with php so it takes long tym to solve a simple problem,pls help me..here is my php code of signup form..

    <?php
    // print_r($_POST);

    //

    if(!empty($_POST))
    {
    $error=0;
    $name=$_POST["name"];
    if($name=="")
    {
    echo "name cannot be empty “;
    $error=1;
    }
    echo “”.$name.””;

    $date_of_birth=$_POST["date_of_birth"];
    if($date_of_birth==””)
    {
    echo “date_of_birth cannot be empty “;
    $error=1;
    }
    echo “”.$date_of_birth.”” ;

    $email=$_POST["email"];
    if($email==””)
    {
    echo “email cannot be empty “;
    $error=1;
    }
    echo “”.$email.” “;

    $password=$_POST["password"];
    $password= md5($password);
    if($password==””)
    {
    echo “password cannot be empty “;
    $error=1;
    }
    echo “”.$password.””;

    $confirm_password=$_POST["cpassword"];
    if($confirm_password==””)
    {
    echo “confirm_password cannot be empty “;
    $error=1;
    }
    echo “”.$confirm_password.” “;

    if($password!=$confirm_password)
    {
    echo “password missmatch “;
    $error=1;
    }
    //if(strlen ($password)>25||strlen($password)<6)
    {

    //echo "password must be between 6 and 25 characters";
    }

    $mobile_number=$_POST["mobile_number"];
    if($mobile_number=="")
    {
    echo "mobile_number cannot be empty “;
    $error=1;
    }
    echo “”.$mobile_number.””;

    $address=$_POST["address"];
    if($address==””)
    {
    echo “address cannot be empty “;
    $error=1;
    }
    echo “”.$address.” “;

    $state=$_POST["state"];
    if($state==””)
    {
    echo “state cannot be empty “;
    $error=1;
    }
    echo “”.$state.” “;

    $district=$_POST["district"];
    if($district==””)
    {
    echo “district cannot be empty “;
    $error=1;
    }
    echo “”.$district.” “;

    $city=$_POST["city"];
    if($city==””)
    {
    echo “city cannot be empty “;
    $error=1;
    }
    echo “”.$city.””;

    $con=@mysql_connect(“localhost”,”root”,””);
    if(!$con)
    {
    echo “did not connect”;
    }
    else
    {

    echo “connected”;

    $db = mysql_select_db(“e-insurance”);
    if(!$db) {
    die(“Unable to select database”);
    }
    $query=”SELECT email FROM `customer` where email=’”.$email.”‘ LIMIT 0 , 30″;
    $query=”UPDATE `e-insurance`.`customer` SET `address` = ‘”.$address.”‘,`password` = ‘”.$password.”‘
    `state` = ‘”.$state.”‘ WHERE `customer`.`name` =’biva’”;

    $a=mysql_query($query);
    if($a)
    {
    if(mysql_num_rows($a)>0)
    {
    $error=1;
    echo “already used “;

    }
    }
    echo “row=”.mysql_affected_rows($con);

    //die();

    echo “account success”;
    mysql_close($con);
    }

    if($error==0)
    {
    $con=@mysql_connect(“localhost”,”root”,””);
    if(!$con)
    {
    echo “did not connect”;
    }
    else
    {

    echo “connected”;

    mysql_select_db(“e-insurance”);

    $query=”INSERT INTO `e-insurance`.`customer` (`id`, `name`, `d_o_b`, `pass`, `mobile`, `address`, `state`, `district`, `city`, `email`) VALUES (NULL, ‘”.$name.”‘, ‘”.$date_of_birth.”‘, ‘”.$password.”‘, ‘”.$mobile_number.”‘, ‘”.$address.”‘, ‘”.$state.”‘, ‘”.$district.”‘,’”.$city.”‘, ‘”.$email.”‘)”;
    // $query=”UPDATE `e-insurance`.`customer` SET `address` = ‘”.$address.”‘,
    //`state` = ‘”.$state.”‘ WHERE `customer`.`name` =’biva’”;
    die(“you have been registered! return to login page“);
    $a=mysql_query($query);
    // echo “row=”.mysql_affected_rows($con);
    //
    // echo “account success”;
    mysql_close($con);
    }

    }
    else
    {
    echo “account unsuccess”;
    }
    }

    ?>
    pls just show me the db connection..name of my db is e-insurance..it shows connected but when i give input it doesnt take it.. :(( pls reply me as soon as possible.

    • http://www.computersneaker.com/ Mudasir Nazir

      You are just Required to update the following part of your code
      Change
      $db = mysql_select_db(“e-insurance”);
      To:
      $db = mysql_select_db(“e-insurance”,$con);
      Reason is that you are selecting database, but you are not directing your code about the server information.
      This is the exact way that you have to use, to let your code work properly.

      • http://techbymak.com Techbymak

        Yes You are right man
        Thank you for the Solution I was facing the same Problem but now I have Solved it thanks a lot.

  • rannel

    hi, i have 1 question, i tried what you did, but after i hit the register button the link direct me to a blank page of registration_script, and no success_register page, dnt know what’s wrong, i need ur help, thanks you so much in advance. :)

    • http://www.computersneaker.com/ Mudasir Nazir

      There is some problem with your query, just make it correct and then try again.

  • Casper

    Nice post, but md5() is NOT encrypt anything. It’s a hash function!

  • http://www.irhwebsites.co.uk Ian Haney

    Hi

    I have just put this tutorial into my website and works perfect but was just wondering how do I get a email sent to the user who just registered to their email address containing their registration info for example the email address, username and password

    Any help would be great

    ps great tutorial

    Kind regards

    Ian

    • http://www.computersneaker.com/ Mudasir Nazir

      simply read my tutorial PHP Email Script here.

  • http://www.irhwebsites.co.uk Ian Haney

    I have figured out getting the registration email sent to the user containing their registration details but the password is being displayed in the md5 format in the email, is there a way of having the password the user enters in displayed

    • http://www.computersneaker.com/ Mudasir Nazir

      Yes, send him in this way, $_POST['password'] instead of sending him md5($_POST['passwword']);
      It will work for you properly, implement this.

  • http://giorgiocefaro.com Giorgio Cefaro

    Hi,
    I think this code is quite obsolete for many many reasons. First of all, mysql_* functions should not be used. You should use PDO or Pear DB.
    Second: security here is a mess. Making Md5 of a password is too weak. SHA1+salt would be better, for example.
    Third: there’s a bunch of free libraries and classes out there for you to not reinvent the wheel. Let’s use them ;-)
    Peace.

    • http://www.damiengrass.com Damien

      I’d use PDO.

      Your attempt to secure it using mysql_real_escape_string() is wrong.

      You’re escaping a user’s password with it.

      What if my password is; 3@#;”$%kahn\

      mysql_real_escape_string() will escape my apostrophe’s, making my password wrong…

    • arsalan

      u r right

  • Zie

    This is not a registration form PHP script, this is a login php script.. ==’

  • shimmer

    I dint understand where you are creating the table ? and where you are viewing the entries..

    sorry i am a newbie !

    • http://www.computersneaker.com/ Mudasir Nazir

      Creating table in mySQL, using third party tool PHPMYADMIN..

  • Matthew

    Getting error no such file, But it is there???

    Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in /srv/disk5/1241697/www/cash.co.nf/registration_script.php on line 9

    Warning: mysql_connect() [function.mysql-connect]: No such file or directory in /srv/disk5/1241697/www/cash.co.nf/registration_script.php on line 9
    Server Information is not Correct

    • http://www.computersneaker.com/ Mudasir Nazir

      Please Check your server configuration, User, password and host . Check them carefully and then start the script again.
      I hope it will work

  • disqus_KBlxDNWJSV

    Thanxs, very helpful for me…

  • xander

    thanks you bro am done with the register part hahaha

  • Ernest Cenizal

    Hi,
    Sir I’m just wondering why my register page only adds one user and then won’t be able to add another even if the registration is successful. The codes are right, it is alike to your codes. What is the problem on my codes? Can you help me sir?

    • http://www.computersneaker.com/ Mudasir Nazir

      Registration will definitely work for first time, you need to run the script every time you want to register another user.

  • add

    i have to show a registration id after the register my form !!! help me
    and also 1 thing …in my register page the id comes from database which is auto increment.

    • engrmudasirmalik

      Dear just use mysql_insert_id() at the end of registration and then save this into some variable or some session, now you are ready to use this wherever you wanted to use this.

  • Inayat Ali jan

    Great work this is really working and helpful for more sample codes for web designing in php and html visit the link:

    lecturshandouts.blogspot.com