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.
Pingback: Login page using PHP | InfoTuts | Programming | PHP |Jquery |HTML5/CSS3|
Pingback: Captcha Code in PHP. | InfoTuts | Programming | PHP |Jquery |HTML5/CSS3|
Hi , I ‘m beginer ,
Please help me to learn PHP
Thanks
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
Pingback: Insert Data in Database using jQuery and PHP | InfoTuts | Programming | PHP |WordPress |HTML5/CSS3
Hi Sanjeev
You can find a nice sign up form in this site http://www.mcwehbe.com
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.
Hi Srilatha,
You can use this registration form and use javascript for validation at client end.
Pingback: Create Simple But Secure Registration form in PHP using PDO - InfoTuts
How can i add more field in a single signup form using jquery and then connect it to the database?
H Rifat,
Please refer this post Dynamically add input fields and submit to database using jQuery. I hope it will help you.
Thanks:
Sanjeev
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.
Can you plz help me to make a registration form which can also add image.I am in a very big problem
Hi Promila,
You can use this form and to upload images using your form you can see this tutorial http://www.infotuts.com/improved-php-script-to-upload-images/. Combine these two tutorials and your form will be ready.
It gives me an error saying that, mysql_connect():Access denied for user ‘root’@’localhost’. Please tell me what’s the problem.
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
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.
Hi Marcus,
Can you show me your code?
in the ‘root’ and password ‘12345’ are those username and password are created in the privileges tab? cause thats my problem as well
Its working now man thanks.
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.
Hello Marcus,
We will surely help you out with your problem and publish a tutorial for the same.
Regards:
Sanjeev
Okay cool I’ll wait.
Please let me know if you’ve posted it
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.
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 http://www.infotuts.com/fetch-record-from-database-using-jquery-and-php/.
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? 🙂