How To Create Registration Page In PHP/MySQL

If you are looking for on How To Create Registration Page In PHP/MySQL then you are at the right place. In this tutorial, we are going to learn on how to create registration page using PHP/MySQL. In this article, the user types their information in the form field to save in the database. After saving the data, the alert message will pop up and said: "User successfully added!". First, we are going to make our database.

Creating our Table

We are going to make our database. To create a database:
  1. Open the PHPMyAdmin
  2. Create a database and name it as "user_registration".
  3. After creating a database name, click the SQL and kindly copy the code below.
  1. --
  2. -- Table structure for table `user`
  3. --
  4.  
  5. CREATE TABLE IF NOT EXISTS `user` (
  6. `user_id` int(11) NOT NULL AUTO_INCREMENT,
  7. `school_number` varchar(100) NOT NULL,
  8. `firstname` varchar(100) NOT NULL,
  9. `middlename` varchar(100) NOT NULL,
  10. `lastname` varchar(100) NOT NULL,
  11. `contact` varchar(100) NOT NULL,
  12. `gender` varchar(100) NOT NULL,
  13. `address` varchar(100) NOT NULL,
  14. `type` varchar(100) NOT NULL,
  15. `level` varchar(100) NOT NULL,
  16. `section` varchar(100) NOT NULL,
  17. `user_image` varchar(100) NOT NULL,
  18. `status` varchar(100) NOT NULL,
  19. `user_added` datetime NOT NULL,
  20. PRIMARY KEY (`user_id`)
Second, we are going to make our form field.

Creating Form Field

This form field that the user types their information to save in the database.
  1. <form method="post" enctype="multipart/form-data" class="form-horizontal form-label-left">
  2. <div class="form-group">
  3. <label class="control-label col-md-4" for="first-name">ID Number <span class="required" style="color:red;">*</span>
  4. </label>
  5. <div class="col-md-2">
  6. <input type="number" name="school_number" id="first-name2" required="required" class="form-control col-md-7 col-xs-12">
  7. </div>
  8. </div>
  9. <div class="form-group">
  10. <label class="control-label col-md-4" for="first-name">First Name <span class="required" style="color:red;">*</span>
  11. </label>
  12. <div class="col-md-3">
  13. <input type="text" name="firstname" placeholder="First Name....." id="first-name2" required="required" class="form-control col-md-7 col-xs-12">
  14. </div>
  15. </div>
  16. <div class="form-group">
  17. <label class="control-label col-md-4" for="first-name">Middle Name
  18. </label>
  19. <div class="col-md-3">
  20. <input type="text" name="middlename" placeholder="MI / Middle Name....." id="first-name2" class="form-control col-md-7 col-xs-12">
  21. </div>
  22. </div>
  23. <div class="form-group">
  24. <label class="control-label col-md-4" for="last-name">Last Name <span class="required" style="color:red;">*</span>
  25. </label>
  26. <div class="col-md-3">
  27. <input type="text" name="lastname" placeholder="Last Name....." id="last-name2" required="required" class="form-control col-md-7 col-xs-12">
  28. </div>
  29. </div>
  30. <div class="form-group">
  31. <label class="control-label col-md-4" for="last-name">Contact
  32. </label>
  33. <div class="col-md-3">
  34. <input type="tel" pattern="[0-9]{11,11}" autocomplete="off" maxlength="11" name="contact" id="last-name2" class="form-control col-md-7 col-xs-12">
  35. </div>
  36. </div>
  37. <div class="form-group">
  38. <label class="control-label col-md-4" for="last-name">Gender <span class="required" style="color:red;">*</span>
  39. </label>
  40. <div class="col-md-4">
  41. <select name="gender" class="select2_single form-control" required="required" tabindex="-1" >
  42. <option value="Male">Male</option>
  43. <option value="Female">Female</option>
  44. </select>
  45. </div>
  46. </div>
  47. <div class="form-group">
  48. <label class="control-label col-md-4" for="last-name">Address
  49. </label>
  50. <div class="col-md-4">
  51. <input type="text" name="address" id="last-name2" class="form-control col-md-7 col-xs-12">
  52. </div>
  53. </div>
  54. <div class="form-group">
  55. <label class="control-label col-md-4" for="last-name">Type <span class="required" style="color:red;">*</span>
  56. </label>
  57. <div class="col-md-4">
  58. <select name="type" class="select2_single form-control" required="required" tabindex="-1" >
  59. <option value="Student">Student</option>
  60. <option value="Teacher">Teacher</option>
  61. </select>
  62. </div>
  63. </div>
  64. <div class="form-group">
  65. <label class="control-label col-md-4" for="last-name">Level <span class="required" style="color:red;">*</span>
  66. </label>
  67. <div class="col-md-4">
  68. <select name="level" class="select2_single form-control" required="required" tabindex="-1" >
  69. <option value="Grade 7">Grade 7</option>
  70. <option value="Grade 8">Grade 8</option>
  71. <option value="Grade 9">Grade 9</option>
  72. <option value="Grade 10">Grade 10</option>
  73. <option value="Faculty">Faculty</option>
  74. </select>
  75. </div>
  76. </div>
  77. <div class="form-group">
  78. <label class="control-label col-md-4" for="first-name">Section <span class="required" style="color:red;">*</span>
  79. </label>
  80. <div class="col-md-3">
  81. <input type="text" name="section" placeholder="Section....." id="first-name2" required="required" class="form-control col-md-7 col-xs-12">
  82. </div>
  83. </div>
  84. <div class="form-group">
  85. <label class="control-label col-md-4" for="last-name">User Image <span class="required">*</span>
  86. </label>
  87. <div class="col-md-4">
  88. <input type="file" style="height:44px;" name="image" id="last-name2" class="form-control col-md-7 col-xs-12">
  89. </div>
  90. </div>
  91. <div class="ln_solid"></div>
  92. <div class="form-group">
  93. <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
  94. <a href="user.php"><button type="button" class="btn btn-primary"><i class="fa fa-times-circle-o"></i> Cancel</button></a>
  95. <button type="submit" name="submit" class="btn btn-success"><i class="fa fa-plus-square"></i> Submit</button>
  96. </div>
  97. </div>
  98. </form>
Third, we are going to make our database connection.

Database Connection

This PHP Script is our database. Copy and paste this then save it as "dbcon.php".
  1. <?php
  2. mysql_select_db('user_registration',mysql_connect('localhost','root',''))or die(mysql_error());
  3. ?>
Fourth, we are going to make our saving PHP Script.

Saving Script - PHP

  1. <?php
  2. include ('include/dbcon.php');
  3. if (isset($_POST['submit'])){
  4.  
  5. if (!isset($_FILES['image']['tmp_name'])) {
  6. echo "";
  7. }else{
  8. $file=$_FILES['image']['tmp_name'];
  9. $image = $_FILES["image"] ["name"];
  10. $image_name= addslashes($_FILES['image']['name']);
  11. $size = $_FILES["image"] ["size"];
  12. $error = $_FILES["image"] ["error"];
  13.  
  14. {
  15. if($size > 10000000) //conditions for the file
  16. {
  17. die("Format is not allowed or file size is too big!");
  18. }
  19.  
  20. else
  21. {
  22.  
  23. move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);
  24. $profile=$_FILES["image"]["name"];
  25. $school_number = $_POST['school_number'];
  26. $firstname = $_POST['firstname'];
  27. $middlename = $_POST['middlename'];
  28. $lastname = $_POST['lastname'];
  29. $contact = $_POST['contact'];
  30. $gender = $_POST['gender'];
  31. $address = $_POST['address'];
  32. $type = $_POST['type'];
  33. $level = $_POST['level'];
  34. $section = $_POST['section'];
  35.  
  36. $result=mysql_query("select * from user WHERE school_number='$school_number' ") or die (mySQL_error());
  37. $row=mysql_num_rows($result);
  38. if ($row > 0)
  39. {
  40. echo "<script>alert('ID Number already active!'); window.location='user.php'</script>";
  41. }
  42. else
  43. {
  44. mysql_query("insert into user (school_number,firstname, middlename, lastname, contact, gender, address, type, level, section, status, user_added)
  45. values ('$school_number','$firstname', '$middlename', '$lastname', '$contact', '$gender', '$address', '$type', '$level', '$section', 'Active', NOW())")or die(mysql_error());
  46. echo "<script>alert('User successfully added!'); window.location='user.php'</script>";
  47. }
  48. }
  49. }
  50. }?>
So, this is it, just follow the steps to have this Registration Page or you can download the full source code below by clicking the "Download Code" button below. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment