Ajax Bootstrap Signup Form with jQuery PHP and MySQL

hello friends, this is my continuation post of previous tutorial, well the previous is just a creating bootstrap signup form along with validation and now in this tutorial we will see Creating Bootstrap Form with Ajax jQuery PHP and MySQL., we already have ajax registration tutorial but that was simple for beginners and this one goes advance, we will see live email availability, Live jQuery validation, and signup process will goes silently without page reload. before proceed you can check the live demo of this tutorial to see how it goes, so let’s get started.

Ajax Bootstrap Signup Form Example with jQuery PHP and MySQL

we will see

  • How to use Remote rule in jQuery Validation
  • Live Email Availability check
  • jQuery Ajax JSON Response
  • Ajax Signup

Looking for Bootstrap Login, Sign Up Modal Forms, Then Here is the Tutorial

In previous tutorial we already covered creating a responsive bootstrap form with validation so i am going to skip the bootstrap form and explaining the above defined title.

Database Table

the database name i have used here is ajax-submit, so create database and copy/paste following sql code into your phpmyadmin to store user details.

  `name` varchar(60) NOT NULL,
  `email` varchar(60) NOT NULL,
  `password` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)


simpel database configuration file created with PDO extension.


 define('DBhost', 'localhost');
 define('DBuser', 'root');
 define('DBPass', '');
 define('DBname', 'ajax-submit');
  $DB_con = new PDO("mysql:host=".DBhost.";dbname=".DBname,DBuser,DBPass);
 }catch(PDOException $e){


simpel php file contains only php code which inserts and creates new user record and store it into mysql table, it will give JSON response as an output. $response = array(); contains json string as status and message. whatever it returns it will be in JSON format.


 header('Content-type: application/json');

 require_once 'config.php';
 $response = array();

 if ($_POST) {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $pass = $_POST['cpassword'];
  $stmt = $DB_con->prepare('INSERT INTO users(name,email,password) VALUES(:name, :email, :pass)');
  $stmt->bindParam(':name', $name);
  $stmt->bindParam(':email', $email);
  $stmt->bindParam(':pass', $pass );
  // check for successfull registration
        if ($stmt->rowCount() == 1) {
   $response['status'] = 'success';
   $response['message'] = '<span class="glyphicon glyphicon-ok"></span> &nbsp; registered sucessfully, you may login now';
        } else {
            $response['status'] = 'error'; // could not register
   $response['message'] = '<span class="glyphicon glyphicon-info-sign"></span> &nbsp; could not register, try again later';
 echo json_encode($response);

Remote Rule

Here’s how you can use Remote Rule within jQuery Validation Rules, it will call “check-email.php” file silently and returns true/false.

email : {
 required : true,
 validemail: true,
 remote: {
  url: "check-email.php",
  type: "post",
  data: {
   email: function() {
   return $( "#email" ).val();

Ajax Signup Code

if there is no validation error the submithandler call the submitForm() function, the function contains ajax method which calls the “ajax-signup.php” page as POST request and print JSON response within div tag and shows as slideDown effect.

function submitForm(){

      type : 'POST',
      async: false,
      url  : 'ajax-signup.php',
      data : $('#register-form').serialize(),
      dataType : 'json',
      success : function(data){
  $('button').html('<img src="ajax-loader.gif" /> &nbsp; signing up...').attr('disabled', 'disabled');
  if ( data.status==='success' ) {
       $('#errorDiv').slideDown(200, function(){
             $('#errorDiv').html('<div class="alert alert-info">'+data.message+'</div>');
       $('#btn-signup').html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Sign Me Up');
    } else {
       $('#errorDiv').slideDown(200, function(){ 
    $('#errorDiv').html('<div class="alert alert-danger">'+data.message+'</div>');
    $('#btn-signup').html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Sign Me Up');
          error: function(){alert('Error!')}      
        return false;