How to Create User Registration Form using PHP and MySQL? [With Source Code]
If you are searching for creating simple user registration form using PHP Scripts with the use of MySQL database, then you are in the right article. So without further more explanation let’s start.
First of all you need to have any server application installed in your PC. Without server application you can not execute any php file because PHP is server side scripting language. So, to make your PC as a server you need to install server application. I am using Wamp Server but you can use any server application software.
Download Wampserver: http://www.wampserver.com/en/
STEPS:
[sociallocker]
1. After installing this application, Start your wampserver, then open your localhost, for this open up your any browsing software and type localhost or 127.0.0.1 in the address bar. Then new page will appear then scroll down and find phpmyadmin and click on that. Then you will be able to see the login page. Login in by entering username and password (Default username is root and password is empty). And then click on new and create one database having any name you want and the click ok, then create table having any number of field you want but i am using four field in this case and click on go. After that, you need to insert the field name like: Name, Address, Phone etc. and then select the length as well as data type as your requirement and then click on save. You can watch the video for this designing part, you may understand better in video.
2. Open your any text editing software, i am using Dreamweaver CC, and then define site and testing server for your Dreamweaver cc, see this article.
3. After completing this task, write the following piece of code and save it in .php extension.
<!doctype html> <?php $servername = "localhost"; $username="root"; $password=""; $dbname="registrationform"; try{ $conn = mysqli_connect($servername, $username,$password,$dbname); echo("successful in connection"); }catch(MySQLi_Sql_Exception $ex){ echo("error in connection"); } if(isset($_POST['submit'])){ $fname=$_POST['fname']; $mname=$_POST['mname']; $lname=$_POST['lname']; $address=$_POST['address']; $gender=$_POST['gender']; $phone = $_POST['phone']; $email=$_POST['email']; $user = $_POST['username']; $pass = $_POST['password']; $register_query = "INSERT INTO `form`(`fname`, `mname`, `lname`, `address`, `gender`, `phone`, `email`, `username`, `password`) VALUES ('$fname','$mname','$lname','$address','$gender','$phone','$email','$user','$pass')"; try{ $register_result = mysqli_query($conn, $register_query); if($register_result){ if(mysqli_affected_rows($conn)>0){ echo("registration successful"); }else{ echo("error in registration"); } } }catch(Exception $ex){ echo("error".$ex->getMessage()); } } ?> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form action="" method="post"> <table align="center"> <tr> <td>Name:</td> <td><input type="text" name="fname" placeholder="enter your first name"></td> </tr> <tr> <td></td> <td><input type="text" name="mname" placeholder="enter your middle name"></td> </tr> <tr> <td></td> <td><input type="text" name="lname" placeholder="enter your last name"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>Address</td> <td><input type="text" name="address" placeholder="enter your address"></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="Male">Male</td> </tr> <tr> <td></td> <td><input type="radio" name="gender" value="female">Female</td> </tr> <tr> <td></td> <td><input type="radio" name="gender" value="others">others</td> </tr> <tr> <td>Phone:</td> <td><input type="tel" name="phone" placeholder="enter your phone no"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>email:</td> <td><input type="email" name="email" placeholder="example@example.com"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>username:</td> <td><input type="text" name="username" placeholder="enter your username"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td>password:</td> <td><input type="password" name="password" value="admin"></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="SignUp"></td> </tr> </table> </form> </body> </html>
4. Open this .php file in any browser you want. 🙂 [/sociallocker] That’s it guyz.
if you have any confusion you can watch the following video: