You are here: Home / Coding / PHP / Basic Registration form in PHP with MySQL database connectivity
Basic Registration form in PHP with MySQL database connectivity

Basic Registration form in PHP with MySQL database connectivity

I am glad to post here my knowledge and techniques used in PHP and MySQL. As you all aware that PHP and MySQL are the most widely used Open Source for websites. Today’s millions of websites and applications are using these free software’s. Personally I feel that this could be next level for front end developers by using PHP and MySQL a HTML developer can make a website more dynamic. Let us discuss How to create a Basic registration form in PHP with database, Its simple and very useful for a basic website dynamic user dynamic registration. Every creative can implement its basic structure to their website. Now Just follow these simple steps and you will find that your first dynamic functional registration form with database entry on every form fill up.

STEP 1: Create Database for inserting values

Go to MySQL,

Create database student;
Qurey OK, 1 row affected (0.00 sec)

mysql> use student
Database changed

mysql> create table student(id int,name varchar(40),email varchar(80),password varchar(40));

Query OK, 0 rows affected (0.05 sec)

STEP 2: Front end code, Make HTML Structure of your registration form

Make a new file registration.html we will make it in PHP later, the structure would be:

<html>
<head>
<title>REGISTRATION FORM</title>
<body>

<form name="registration" method="post" action="registration.php">
<!-- we will create registration.php after registration.html -->
USERNAME:<input type="text" name="name" value=""></br>
EMAIL-ID:<input type="text" name="email" value=""></br>
PASSWORD:<input type="text" name="password" value=""></br>
RE-PASSWORD:<input type="text" name="repassword" value=""></br>
<input type="submit" name="submit" value="submit">
</form>

</body>
</head>
</html>

STEP 3: For Database connectivity using MySQL

Create a connect.php file for basic database connection use that default code as below

<?php
$hostname="localhost"; //local server name default localhost
$username="root";  //mysql username default is root.
$password="";       //blank if no password is set for mysql.
$database="student";  //database name which you created
$con=mysql_connect($hostname,$username,$password);
if(! $con)
{
die('Connection Failed'.mysql_error());
}

mysql_select_db($database,$con);
?>

STEP 4: Finally create a registration.php page to get value of all fields shown in HTML page

Here a Front end developer can write some own code in PHP, Read the code and understand this basic structure line by line you will find it very easy.

<?php     //start php tag
//include connect.php page for database connection
Include('connect.php')
//if submit is not blanked i.e. it is clicked.
If(isset($_REQUEST['submit'])!='')
{
If($_REQUEST['name']=='' || $_REQUEST['email']=='' || $_REQUEST['password']==''|| $_REQUEST['repassword']=='')
{
Echo "please fill the empty field.";
}
Else
{
$sql="insert into student(name,email,password,repassword) values('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."', '".$_REQUEST['repassword']."')";
$res=mysql_query($sql);
If($res)
{
Echo "Record successfully inserted";
}
Else
{
Echo "There is some problem in inserting record";
}

}
}

?>

Conclusion

By following step by step procedure provided above a basic registration form can be created. So best of luck for your first PHP code Get the code snippets here.

About Akshma Sharma

Web & PHP Developer, with a zeal experience of web and application development on various platform like Android, iOS, PHP, MySQL, CMS, Wordpress, Joomla, Magento and Drupal.

49 comments

  1. vutechworldevc@gmail.com'

    i am getting error in registration.php at 5th line the error is
    Parse error: syntax error, unexpected T_IF in /home/a3403532/public_html/registration.php on line 5

    how to clear it sir please help me out here

  2. akshma@creativealive.com'

    Hi,

    It was my mistake please use ;(semicolon) after include(connect.php);

    Thanks

  3. akshma9sharma@gmail.com'

    code snippets updated for registration.php as below:


    < ?php //start php tag //include connect.php page for database connection include('connect.php'); //if submit is not blanked i.e. it is clicked. if(isset($_REQUEST['submit'])!='') { if($_REQUEST['name']=='' || $_REQUEST['email']=='' || $_REQUEST['password']==''|| $_REQUEST['repassword']=='') { Echo "please fill the empty field."; } Else { $sql="insert into student(name,email,password) values('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."')"; $res=mysql_query($sql); if($res) { Echo "Record successfully inserted"; } Else { Echo "There is some problem in inserting record"; } } } ?>

  4. rainetmc@gmail.com'

    it keeps giving me “There is some problem in inserting record.., cant seem to find whats wrong.

  5. kenji_chin93@hotmail.com'

    why when i register , if just comeout There is some problem in inserting record ?? i ady fill in the form . pls help

  6. udhay.besant@gmail.com'

    hi, just give your update query

  7. akshma@creativealive.com'

    Hi,

    @ raine ,Dhaos
    Plz check your if($res) condition.Here your result may be null that’s why it is going in else part.
    Check your query just simply echo $sql;
    It will show what is going in your sql query.

    @udhaya

    $sql=”insert into student(name,email,password) values(‘”.$_REQUEST[‘name’].”‘, ‘”.$_REQUEST[’email’].”‘, ‘”.$_REQUEST[‘password’].”‘)”;

    This is the query you have to use.

    Thanks

    It is

  8. sangarnikhil282@gmail.com'

    Line 5 error: parse error
    Parse error: syntax error, unexpected T_IF in C:\wamp\www\CARSHOPPINNG\registration.php on line 5

    • timothyg127@gmail.com'

      Hello on line 4 you have to put a semicolin after include = (‘connect.php’) “;” I put it in to qoutations and if I helped please please visit my website

  9. nedo_kanat@hotmail.com'

    this msg comes up when i click on submit button … please fill the empty field.

  10. juniorlubaki2002@yahoo.fr'

    help me with this message!! Parse error: syntax error, unexpected ‘If’ (T_IF) in /home/vhosts//sites/junior/registration.php on line 5

  11. juniorlubaki2002@yahoo.fr'

    i got this message help plz Parse error: syntax error, unexpected ‘742805’ (T_LNUMBER), expecting variable (T_VARIABLE) or ‘$’ in /home/vhosts/lubiengajunior.orgfree.com/sites/junior/connect.php on line 7

  12. juniorlubaki2002@yahoo.fr'

    hello whtas this message means ? after submit Connection FailedAccess denied for user ‘apache’@’localhost’ (using password: NO)

  13. juniorlubaki2002@yahoo.fr'

    Please i need help , after submit this’s the msg I got Connection FailedAccess denied for user ‘apache’@’localhost’ (using password: NO)

  14. akshma@creativealive.com'

    Hi All,

    @ junior
    1)Please check your mysql password you are using in connect.php.The password you are using may be different from your connect.php.If you have no password for your mysql just blank for $password=””; if you have set any password then put it in quotes.Then FailedAccess denied for user ‘apache’@’localhost’ (using password: NO) will be resolved.

    @Nikhil & junior

    2) Parse error: syntax error, unexpected ‘If’ (T_IF) in to remove this plz use semicolon after include(“connect.php”);

    @Bone
    This is just a validation for empty field if you are going to post an empty field.

    Thanks

  15. mathivel992@gmail.com'

    hi, i need procedure for creating database in advance wordpress.

  16. juniorlubaki2002@yahoo.fr'

    Hi plz help after submit: Connection FailedAccess denied for user ‘root’@’localhost’ (using password: YES)

  17. ayub_azam2012@yahoo.com'

    hi. i am php beginner. i want to be a php programmer but i need help to do programming in php. anybody can help me ?
    This artical really helped me more than i expect.

  18. juniorlubaki2002@yahoo.fr'

    Hi plz help after submit: Connection FailedAccess denied for user ‘root’@’localhost’ (using password: YES)

  19. pjain606@gmail.com'

    this warning is coming please help!
    mysql_connect(): Access denied for user ‘root’@’localhost’ (using password: NO) in D:\xampp\htdocs\student\connect.php on line 6
    Connection FailedAccess denied for user ‘root’@’localhost’ (using password: NO)

  20. pjain606@gmail.com'

    help help help!
    it is not connecting to database. how can i see if entry of data is been done or not in to database when i registered.

  21. jc17real@gmail.com'

    great tutorial!!!!!!!!!!! can you create a log in tutorial where users can log in using their information provided in this tutorial???

    thanks

  22. omgaur2005@gmail.com'

    I want simple file uploading code in php that can be used to uploads various type files in secure manner.

  23. norman.ansao@gmail.com'

    hi what about same username? please reply thnx

  24. sean.valderramait@gmail.com'

    To Those who gets Error or the Display “There is some problem in inserting record”

    Step1: Review your Code.
    Step2: make your you have the Correct Field in the Database and Correct naming of the textbox in your HTML.

    I Hope it Helps… 🙂

  25. mandavamohanakrishna@gmail.com'

    i got this Record successfully inserted

    how can i log into it

  26. rajisairam07@gmail.com'

    There is some problem in inserting record

  27. masonwoolcock@wildmail.com'

    I’ve been browsing online more than 4 hours today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my view, if all
    web owners and bloggers made good content as you did, the net will be
    a lot more useful than ever before.

  28. adityakv2222@gmail.com'

    plz any one can send to me coding of a slider on my Email.Id

    adityakv2222@gmail.com

  29. barkat_a91@yahoo.com'

    please help me, when i submit it gives me an error.
    ( ! ) Parse error: syntax error, unexpected ‘If’ (T_IF) in C:\wamp\www\registration.php on line 5

  30. karolbartels@aol.com'

    I think that is among the so much significant information for me.
    And i’m satisfied studying your article. However
    want to remark on few general things, The web site
    style is wonderful, the articles is in point of fact excellent
    : D. Excellent process, cheers

  31. johnd503@gmail.com'

    Hey very nice blog!! Man .. Beautiful .. Amazing .. I’ll bookmark your website and take the feeds alsoI am happy to find a lot of useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . . dekdecgfkkbk

  32. smithd6@gmail.com'

    Valuable information. Fortunate me I discovered your web site by chance, and I am surprised why this coincidence didn’t happened in advance! I bookmarked it. dkbegebgffddcabe

  33. ravijoon52@gmail.com'

    I really appreciate your all valuable comments and suggestion. Although i have learn a lot form this post.

  34. nehan173@gmail.com'

    plz help me whenever i try to register it shows me “There is some problem in inserting record”..

  35. aldover.emmanuel@gmail.com'

    so i edited the code to only use 2 inputs
    and i did this to test the values “Echo $sql;”

    but it displayed this.

    There is some problem in inserting record insert into student(name,email) values(‘da’,’fa’)

  36. pavithra.jomei@gmail.com'

    error come bcos u gave database and table name as same

  37. mathivel992@gmail.com'

    useful information for beginners. it will help self learning process. I think this is best place to learn php.
    Regards..
    mathivel

  38. honeyzehri0987@gamail.com'

    im new i wana learn about web im not geting tha
    t how to start

  39. mathivel992@gmail.com'

    yes mr. abc i checked this code it is working when i cleared table name

  40. shaneswift@inbox.com'

    Hey There. I discovered your weblog the usage of msn. That is a really neatly written article.

    I will be sure to bookmark it and come back to read more of
    your useful info. Thanks for the post. I will definitely comeback.

  41. dominik_macfarlan@live.com'

    Pretty great post. I simply stumbled upon your blog and wanted to say that I have truly enjoyed browsing your
    blog posts. In any case I will be subscribing for your rss feed and I am hoping you write once more
    soon!

  42. annettaraphael@inbox.com'

    I’ve been exploring for a little bit for any high quality articles or weblog posts on this kind of house
    . Exploring in Yahoo I finally stumbled upon this web site.
    Reading this info So i’m glad to exhibit that I’ve a very excellent uncanny feeling I discovered just
    what I needed. I such a lot for sure will make certain to
    don?t overlook this web site and give it a glance regularly.

  43. lina.pascal@inbox.com'

    Having read this I thought it was rather informative.
    I appreciate you finding the time and energy
    to put this content together. I once again find myself spending way too much time both reading and leaving comments.
    But so what, it was still worth it!

  44. girachmohsin@gmail.com'

    you all must be refer the book web and application development ed.n -8 its really help you all.

  45. waqas_j4u@yahoo.com'

    i have made the above mention program and form working correctly but i have problem here i want to fetch data from database.someone tell me the procedure regards…wiki

  46. Thanks to all for your valuable comments and suggestions… Cheers!!!

Scroll To Top