Bootstrap Signup Form with Email Availability Check using jQuery, PHP, and MySQL

Bootstrap Signup Form with Email Availability Check using jQuery PHP and MySQL

In this tutorial, we are going to create Bootstrap Signup Form with Email Availability Check using jQuery PHP and MySQL. This tutorial created to the advanced level of programming. Features of this simple tutorial are to check the email availability, live jQuery validation in every field, and signup process without refreshing the whole page. You can also check the live demo of this simple tutorial, so you can get an idea and you can try this out, let's start coding. Example email - [email protected] Download the source code below and try the existing email to sign up again to check if it is available or not.

You can learn:

  • Using jQuery Validation
  • Email Availability Check
  • Using JSON Response
  • Signup Using Ajax
Result

Database Table

For creating a database, kindly copy and paste this following SQL source code into your PHPMyAdmin to insert user details.
  1. --
  2. -- Table structure for table `users`
  3. --
  4.  
  5. CREATE TABLE `users` (
  6.   `id` INT(11) NOT NULL,
  7.   `name` VARCHAR(60) NOT NULL,
  8.   `email` VARCHAR(60) NOT NULL,
  9.   `password` VARCHAR(255) NOT NULL
  10. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  11.  
  12. --
  13. -- Dumping data for table `users`
  14. --

Database Connection

This is simple database connection file using PDO extension. Save it as "config.php".
  1. <?php
  2.         define('DataBasehost', 'localhost');
  3.         define('DataBaseuser', 'root');
  4.         define('DataBasePass', '');
  5.         define('DataBasename', 'ajaxsubmit');
  6.        
  7.         try{
  8.                
  9.                 $DataBase_con = new PDO("mysql:host=".DataBasehost.";dbname=".DataBasename,DataBaseuser,DataBasePass);
  10.                
  11.         }catch(PDOException $sample){
  12.                
  13.                 die($sample->getMessage());
  14.         }
  15. ?>

INSERT Statement using PDO Extension

It contains PHP source code using PDO extension which you can insert new users details and store it into MySQL Table. Copy and paste and save it as "ajax-signup.php".
  1. <?php
  2.  
  3.         header('Content-type: application/json');
  4.  
  5.         require_once 'config.php';
  6.        
  7.         $response = array();
  8.  
  9.         if ($_POST) {
  10.                
  11.                 $name = $_POST['name'];
  12.                 $email = $_POST['email'];
  13.                 $pass = $_POST['cpassword'];
  14.                
  15.                 // sha256 password hashing
  16.                 $password = hash('sha256', $pass);
  17.                
  18.                 $statement = $DataBase_con->prepare('INSERT INTO users(name,email,password) VALUES(:name, :email, :pass)');
  19.                 $statement->bindParam(':name', $name);
  20.                 $statement->bindParam(':email', $email);
  21.                 $statement->bindParam(':pass', $password);
  22.                 $statement->execute();
  23.                
  24.                 // check for successfull registration
  25.         if ($statement->rowCount() == 1) {
  26.                         $response['status'] = 'success';
  27.                         $response['message'] = '<span class="glyphicon glyphicon-ok"></span> &nbsp; registered sucessfully, you may login now';
  28.         } else {
  29.                        
  30.             $response['status'] = 'error'; // could not register
  31.                         $response['message'] = '<span class="glyphicon glyphicon-info-sign"></span> &nbsp; could not register, try again later';
  32.         }      
  33.         }      
  34.         echo json_encode($response);
  35. ?>

Email Availability Check

This simple PHP source code using PDO extension use to check the email if it is available or not. It will give a message to a new user if it is already taken the email or not.
  1. <?php
  2.  
  3.         require_once 'config.php';
  4.  
  5.         if (isset( $_POST['email'] ) && !empty($_POST['email'])) {
  6.                 $email = $_POST['email'];
  7.                 $query = " SELECT email FROM users where email = :email ";
  8.                 $statement = $DataBase_con->prepare($query);
  9.                 $statement->execute(array(':email'=>$email));
  10.                
  11.                 if ($statement->rowCount() == 1) {
  12.                         echo 'false'; // email already taken
  13.                 } else {
  14.                         echo 'true';
  15.                 }
  16.         }
  17. ?>

Output

Email Availability Check Result Field Validation Result Note: You can customize the form whatever your desired design by changing the CSS. Hope that this simple yet useful tutorials that I created may help you to your future projects. 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