Here in this tutorial, we make you learn how to create simple registration form with proper validation using jQuery and database connectivity using PHP.

We have created a simple HTML form with four fields- Name, Email, Password., and Confirm Password.  There is a  jQuery function for complete validation and user data get inserted through PHP script.

Before inserting into database, sanitization and validation on email is done using PHP. Also, user input email get checked into database for it’s existence, if it exist then, user must enter another email.

You can download our zip file or simply follow our code and edit it to use.

-:See Also:-

jQuery  login Form


HTML File: registration.html

Given below our complete HTML code , copy to use it.

<!DOCTYPE html>
<title>Registration Form Using jQuery - Demo Preview</title>
<meta name="robots" content="noindex, nofollow">
<!-- Include CSS File Here -->
<link rel="stylesheet" href="css/style.css"/>
<!-- Include JS File Here -->
<script src=""></script>
<script type="text/javascript" src="js/registration.js"></script>
<div class="container">
<div class="main">
<form class="form" method="post" action="#">
<h2>Create Registration Form Using jQuery</h2>
<label>Name :</label>
<input type="text" name="dname" id="name">
<label>Email :</label>
<input type="text" name="demail" id="email">
<label>Password :</label>
<input type="password" name="password" id="password">
<label>Confirm Password :</label>
<input type="password" name="cpassword" id="cpassword">
<input type="button" name="register" id="register" value="Register">

jQuery File:  registration.js

Given below our complete jQuery code.

$(document).ready(function() {
$("#register").click(function() {
var name = $("#name").val();
var email = $("#email").val();
var password = $("#password").val();
var cpassword = $("#cpassword").val();
if (name == '' || email == '' || password == '' || cpassword == '') {
alert("Please fill all fields...!!!!!!");
} else if ((password.length) < 8) {
alert("Password should atleast 8 character in length...!!!!!!");
} else if (!(password).match(cpassword)) {
alert("Your passwords don't match. Try again?");
} else {
$.post("register.php", {
name1: name,
email1: email,
password1: password
}, function(data) {
if (data == 'You have Successfully Registered.....') {

PHP Script: register.php

Below script executes for inserting data into database.

$connection = mysql_connect("localhost", "root", ""); // Establishing connection with server..
$db = mysql_select_db("college", $connection); // Selecting Database.
$name=$_POST['name1']; // Fetching Values from URL.
$password= sha1($_POST['password1']); // Password Encryption, If you like you can also leave sha1.
// Check if e-mail address syntax is valid or not
$email = filter_var($email, FILTER_SANITIZE_EMAIL); // Sanitizing email(Remove unexpected symbol like <,>,?,#,!, etc.)
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "Invalid Email.......";
$result = mysql_query("SELECT * FROM registration WHERE email='$email'");
$data = mysql_num_rows($result);
$query = mysql_query("insert into registration(name, email, password) values ('$name', '$email', '$password')"); // Insert query
echo "You have Successfully Registered.....";
echo "Error....!!";
echo "This email is already registered, Please try another email...";
mysql_close ($connection);

My SQL Code Segment:

To create database and table, execute following codes in your My SQL .

CREATE TABLE registration(
name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
password varchar(255) NOT NULL,

CSS File: style.css

Styling HTML Elements.

/* Below line is used for online Google font */
@import url(;
text-align: center;
font-size: 24px;
margin-bottom: 30px;
width: 960px;
height: 610px;
margin:50px auto;
font-family: 'Droid Serif', serif;
width: 320px;
padding: 10px 55px 40px;
background-color: rgba(187, 255, 184, 0.65);
border: 15px solid white;
box-shadow: 0 0 10px;
border-radius: 2px;
font-size: 13px;
input[type=text],[type=password] {
width: 97.7%;
height: 34px;
padding-left: 5px;
margin-bottom: 20px;
margin-top: 8px;
box-shadow: 0 0 5px #00F5FF;
border: 2px solid #00F5FF;
color: #4f4f4f;
font-size: 16px;
color: #464646;
text-shadow: 0 1px 0 #fff;
font-size: 14px;
font-weight: bold;
#register {
font-size: 20px;
margin-top: 15px;
background: linear-gradient(#22abe9 5%, #36caf0 100%);
border: 1px solid #0F799E;
padding: 7px 35px;
color: white;
text-shadow: 0px 1px 0px #13506D;
font-weight: bold;
border-radius: 2px;
cursor: pointer;
width: 100%;
background: linear-gradient(#36caf0 5%, #22abe9 100%);

Pabbly Form Builder


This was all about to create simple registration form with validation and database connectitvity.  Hope you like it, Keep reading our other blogs.

You may also like –