How to Create Registration Page in PHP/MySQL

Related code: How to Create Secure Registration Page in PHP/MySQL This is a simple tutorial that will teach you on how to create a simple registration form using PHP/MySQL with JavaScript for input validation. This tutorial will not teach you on how to create a good design but rather to give you knowledge on how to create a fully functional registration form.

Creating our Table

First we are going to create our database which stores our data. To create a database: 1. Open phpmyadmin 2. Click create table and name it as simple_login. 3. Then name the database as "registration". 4. After creating a database name, click the SQL and paste the below code. CREATE TABLE IF NOT EXISTS `member` ( `mem_id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(30) NOT NULL, `password` varchar(30) NOT NULL, `fname` varchar(30) NOT NULL, `lname` varchar(30) NOT NULL, `address` varchar(100) NOT NULL, `contact` varchar(30) NOT NULL, `picture` varchar(100) NOT NULL, `gender` varchar(10) NOT NULL, PRIMARY KEY (`mem_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

Creating The Form

Next step is to create a form and save it as index.php. To create a form, open your HTML code editor and paste the code below after the tag. Registration
First Name:
Last Name:
Gender:
Address:
Contact No.:
Username:
Password:

Creating our Connection

Next step is to create a database connection and save it as "connection.php". This file is used to connect our form to database. This file serves as a bridge between our form and our database.

Writing Our Save Script

Next step is to create our script that save our input data to database and save it as code_exec.php.

Validating The Input

To add some input validation using javascript, add the code below in the head tag of your index.php file. Input validation is used to make sure that all input field are filled out before saving the to database. That's it! You've been successfully created your simple registration form with javascript for the input validation. Registration using php, input validation using javascript. Update: I have created another tutorial using a server side validation. And I am also using PDO to secure the registration page. Click here to see my latest update How to Create Registration Page in PHP/MySQL Using PDO Query. Related code: How to Create Secure Registration Page in PHP/MySQL

Comments

Submitted byslimfiton Tue, 06/12/2012 - 14:52

Thanks for the tutorial...its really nice....but for the picture uploading.....is it text or picture....am a little bit confused there....maybe you should please shed more light to that.....

Yeah, i would really like this portion to be treated. I am in need of the picture section to work well. Thank you. Cheers!

Guys, you don't store pictures in a database. You store the location of the picture, hence the datatype will be text. This doesn't resolve how to browse/upload/resize/store a picture, which I believe is beyond the scope of this tutorial. Hope this sheds some light on why the datatype is (and should be) text.

Submitted byAnonymous (not verified)on Tue, 10/02/2012 - 21:50

Nice, but the picture is in text datatype, and secondly no upload file input for the picture?it says text. This tutorial doesn't help in picture upload. but great work!
Submitted bywaistbarns (not verified)on Wed, 07/27/2016 - 03:05

In reply to by Anonymous (not verified)

change the text type for input type to file i.e
Submitted byAnonymous (not verified)on Sat, 10/20/2012 - 14:36

realy nice tutorial !!!!!!!!!!! thanks for the same
Submitted byJimm64 (not verified)on Sat, 11/10/2012 - 03:52

Too many testing the other script. found error. but this code works perfect. im combine with login. it just ALL PERFECT thanks. :)
Submitted bysasi (not verified)on Fri, 11/16/2012 - 17:18

I learn the concept easily through your coding. i got one error msg when i click for register link.. "Undefined index: remarks in C:\wamp\www\Simple_login\register.php on line 7" remarks variable is not present in table. but i create that variable again i got error. help me to rectify. beginner to php mysql. Thanks,
Submitted byAnonymous (not verified)on Fri, 11/30/2012 - 20:56

thank you so much for this tutorial, it works perfectly. I need this for a fourth year project. Took me less than 5 minutes to add it to my site. I love you!!
Submitted byAnonymous (not verified)on Sun, 12/02/2012 - 12:54

okay how do i get rid of coloums like all i want is username and password and i managed to mix it all around so username and password are required because before they weren't can u send me an entire code and the check code that is supposed to be in the head that works and is just Username: and Password: and the database code it would really help alot
Submitted byAnonymous (not verified)on Thu, 12/20/2012 - 02:42

Where are you pulling this info from? $remarks=$_GET['remarks'];
Submitted byAnonymous (not verified)on Mon, 12/24/2012 - 08:17

In reply to by Anonymous (not verified)

An answer for this question?
Submitted byangela22on Thu, 01/03/2013 - 14:52

i have copy paste all your code and upload with cpannel in my server
but when i put detail and submit it:NO ANY RESPONSE:??

Submitted byAnonymous (not verified)on Wed, 01/09/2013 - 01:08

wow, very helpful and precisely explained.
Submitted byAnonymous (not verified)on Tue, 01/22/2013 - 15:01

i dont get it.
Submitted bydwel (not verified)on Tue, 12/15/2015 - 16:10

In reply to by Anonymous (not verified)

i dont get it
Submitted byAnonymous (not verified)on Thu, 01/24/2013 - 17:12

Plese, I would like download all files in .zip/rar. Could you link the data here?
Submitted byAnonymous (not verified)on Fri, 02/01/2013 - 13:41

my form is not submitting values into the table..:(
Submitted byAnonymous (not verified)on Wed, 03/20/2013 - 16:47

In reply to by Anonymous (not verified)

do you mean when you try to submit it say success and when you check the DB and Table its still empty - - - - hahaha - - - same with me - - - - but i solved it immediately IDK maybe many ddnt notice or just ignore it NOTICE in creating the db the ARRANGMENT OF COLUMNS e.g memid,username,password . . . IT should be the same in "insert query" e.g mysql_query("INSERT INTO members (username, password,. . . .) VALUES ('$username', '$password', . . . . .)"); -------- get it.? thats how i solved it
Submitted byrachysykr (not verified)on Fri, 05/09/2014 - 08:25

In reply to by Anonymous (not verified)

Help me to solve it? anyone??  <table> <php>
Submitted byAnonymous (not verified)on Mon, 02/04/2013 - 02:30

Tried and Tied :( Please help me in solving these errors Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/xxx/public_html/zzz.com/new/code_exec.php:1) in /home/xxx/public_html/zzz.com/new/code_exec.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xxx/public_html/zzz.com/new/code_exec.php:1) in /home/xxx/public_html/zzz.com/new/code_exec.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/public_html/zzz.com/new/code_exec.php:1) in /home/xxx/public_html/zzz.com/new/code_exec.php on line 13 Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/xxx/public_html/zzz.com/new/code_exec.php on line 14
Submitted byAnonymous (not verified)on Sat, 02/09/2013 - 18:55

he he
Submitted byAnonymous (not verified)on Wed, 02/20/2013 - 22:29

Im have problem with $remarks=$_GET['remarks']; anybody got a solution to that ?
Submitted byAnonymous (not verified)on Fri, 02/22/2013 - 19:02

Thanks
Submitted byAnonymous (not verified)on Fri, 03/15/2013 - 13:38

error on remark what should i do?
Submitted byAnonymous (not verified)on Fri, 03/15/2013 - 16:35

Worked well For me... Well compiled for a beginner...
Submitted byAnonymous (not verified)on Sun, 03/17/2013 - 10:13

yes i did it but i need also the code for logging in can you help me guys ? im about 1 week in trying and trying to code a register and log in i php. this is for my project . help me please?
Submitted byAnonymous (not verified)on Fri, 03/22/2013 - 15:25

Your codes were excellent but I'm experiencing error in $remarks=$_GET['remarks']. Can you please help me with this error? Thank you so much in advance.
Submitted byAnonymous (not verified)on Tue, 03/26/2013 - 04:26

Notice: Undefined index: remarks in C:\xampp\htdocs\index.php on line 76
Submitted byAnonymous (not verified)on Sun, 03/31/2013 - 09:51

You know... there are 25k+ people have looked at this page and I bet a lot have benefitted from this awesome nicely laid out tutorial and didn't bother to post a 'thank you'. I'm not going to be one of them. So... Thank you!!!!
Submitted byAnonymous (not verified)on Sun, 03/31/2013 - 19:26

i am getting a notice that undefined index:remarks
other than that all the code is working and registration is also successfull.please help in that error...

Submitted byAnonymous (not verified)on Mon, 04/01/2013 - 01:31

just replace this line in index.php: 7. $remarks=$_GET['remarks']; with this instead. 7. if (!isset($_GET['remarks'])) {$remarks=""; } else {$remarks=$_GET['remarks']; } It tests to see if remarks is set. If it isn't, it will set it to empty.
Submitted byAnonymous (not verified)on Wed, 04/24/2013 - 14:48

In reply to by Anonymous (not verified)

thank you very much. . . :D
Submitted byAnonymous (not verified)on Fri, 06/21/2013 - 02:01

In reply to by Anonymous (not verified)

Thnx alot brother :)
Submitted byAnonymous (not verified)on Fri, 07/12/2013 - 01:13

In reply to by Anonymous (not verified)

thannks that cleared the error. but now have another problem Could not select database
Submitted bywsm (not verified)on Sat, 09/07/2013 - 05:49

In reply to by Anonymous (not verified)

change ur database name in connection.php to simple_login...where it is wrongly entered as registration.
Submitted bysapuu (not verified)on Mon, 08/19/2013 - 21:33

In reply to by Anonymous (not verified)

thank you

Good day to you, please i just replace -$remarks=$_GET['remarks]-with (if -!isset($_GET['remarks'])) {$remarks=""; } else {$remarks=$_GET['remarks']; }- but I am now getting another error on the same line -Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\unibenictwebform\index.php on line 7- please help
Submitted byAnonymous (not verified)on Thu, 03/30/2017 - 02:57

In reply to by Anonymous (not verified)

Thank you so much you are a life saver for giving the correct statement and thank you argie for this very detailed work
Submitted byAnonymous (not verified)on Mon, 04/08/2013 - 19:22

i tried this code.but i got errors.
Submitted byAnonymous (not verified)on Wed, 04/10/2013 - 18:23

hello am newly about this php.am getting errors in the validation.
Submitted byAnonymous (not verified)on Sat, 04/13/2013 - 04:09

thanks a lot
Submitted byAnonymous (not verified)on Mon, 04/22/2013 - 09:44

Good

Add new comment