Create Registration Form using PHP and Mysql

Abhigyan Singh 12th Jul 2020

In this tutorial, I will explain that how to create a simple registration form in PHP and mysql. Registration form is necessary for all online activities for small website to a big web portal. Registration means providing necessary information to the website for further activities.

The website will store all the information into their database and when you will again visit that website you just need to login no need to provide detail again.

Read: Download Login Form in PHP and Mysql

So the registration form has important role in present website.
Here, we are using javascript validations for input fields. So user can learn different type of validation in javascript like simple text field, email ID etc.

Now we will see how to create Registration Form in PHP and Mysql step by step.
Steps are given below:
There are four files for Registration Form:

  1. dbConfig.php
  2. register.php
  3. registerAction.php
  4. validate.js

The dbConfig.php file looks like this:

define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", ""); // set database user
define ("DB_PASS",""); // set database password
define ("DB_NAME",""); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

Here just change the above value like Host name, database user name, database password and database name.

The register.php file looks like this:

<form action="registerAction.php" method="post" name="frmregister">
<table border="0" class="form">
<td><input name="name" size="30" type="text" /></td>
<th><strong>Nick Name:</strong></th>
<td><input name="nick_name" size="30" type="text" /></td>
<td><input name="email" size="30" type="text" /></td>
<td><input name="password" size="30" type="password" /></td>
<td><input alt="Submit" type="submit" value="Submit" /> <input alt="Reset" type="reset" value="Reset" /></td>

The registerAction.php file looks like this:

include "dbConfig.php";
if($_POST[ 'name' ]!="") {
$name = mysql_real_escape_string($_POST["name"]);
$nick_name = mysql_real_escape_string($_POST["nick_name"]);
$email = mysql_real_escape_string($_POST["email"]);
$password = mysql_real_escape_string($_POST["password"]);

$sql = "insert into members set name='".$name."', nick_name='".$nick_name."', email='".$email."', password='".md5($password)."' ";
$sql = mysql_query($sql);

$msg = '
<p class = "tanx"-->Thank you for completing your online registration form!.&#39;;
$msg = &quot;Your enquiry sending failed&quot;;


That’s all about Registration Form.

Authored By Abhigyan Singh

He is a continuous blogger and has blogged on different topic. He loves to surf Internet and always trying to get new Idea about new Technology and Innovations and sharing these great information to all the technology lovers.

Also on DiscussDesk