New to our community ?

Discover a world of possibilities! Join us and explore a vibrant community where ideas flourish and connections thrive.

One of Our Valued Members

Thank you for being part of our community. Your presence enriches our shared experiences. Let's continue this journey together!

Home php codes Check Email is Already Registered in Database using Ajax and JavaScript.

Check Email is Already Registered in Database using Ajax and JavaScript.


Hey,Welcome to shortlearner, today we will see how to check that email is already registered in database, with the use of ajax and java-script.
Most of the time we see that the user is registering same  email id  in database and it is registered in the database without checking that it was already registered in database.

but with the help of ajax and java-script we can show our users that their email is registered or not registered in our database by showing them a message.

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

This will help to prevent redundancy of data in our database.
In this tutorial we will use maxcdn classes of bootstrap , AJAX and JavaScript for maximize output.
put the below maxcdn classes of bootstrap inside the head section of your html code.

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="">
<!-- jQuery library -->
<script src=""></script>
<!-- Latest compiled JavaScript -->
<script src=""></script>
.btn-facebook {
    color: #ffffff;
    -webkit-text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
    background-color: #2b4b90;
    *background-color: #133783;
    background-image: -moz-linear-gradient(top, #3b5998, #133783);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#3b5998), to(#133783));
    background-image: -webkit-linear-gradient(top, #3b5998, #133783);
    background-image: -o-linear-gradient(top, #3b5998, #133783);
    background-image: linear-gradient(to bottom, #3b5998, #133783);
    background-repeat: repeat-x;
    border-color: #133783 #133783 #091b40;
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3b5998', endColorstr='#ff133783', GradientType=0);
    filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
    .btn-facebook[disabled] {
        color: #ffffff;
        background-color: #133783 !important;
        *background-color: #102e6d !important;
    .btn-facebook:active, {
        background-color: #0d2456 9 !important;

we use external stylesheet in this tutorial, so put the above css in the head section of your html code..


<!DOCTYPE html>
  <title>Check Email is Already Registered </title>
<style type="text/css" href="css/style.css"></style>
            <h3>Login via site</h3>
            <form accept-charset="UTF-8" role="form">
                  <input placeholder="" name="email" type="text" id="email"  onBlur="checkAvailability()">
                  <span id="email-availability-status"></span>    
                <input placeholder="Password" name="password" type="password" value="">
                    <input name="remember" type="checkbox" value="Remember Me"> Remember Me
              <input type="submit" value="Login">
                    <input type="submit" value="Login via facebook">

Now we will call the JavaScript function which will trigger our ajax query. in ajax query we will call the check-availability page . in check-availability  page we will run our php script that will compare the email id from the database,
if the email is registered in database, a message will popup in red color and show the user that email is already registered, otherwise the popup is appear in green color and show the user that email id is available.

          function checkAvailability() {
url: "check_availability.php",
type: "POST",
error:function (){}

Put the Above  JavaScript in the head section of html code.


$con= mysqli_connect("localhost","root","","dbname");
if(!empty($_POST["email"])) {
	$qry="SELECT email FROM user WHERE email='" . $_POST["email"] . "'";
$result = mysqli_query($con,$qry);
$row = mysqli_fetch_row($result);
echo "<span style='color:red'> Email already exists .</span>";
 echo "<script>$('#email-availability-status').prop('disabled',true);</script>";
} else{
	echo "<span style='color:green'> Email available for Registration .</span>";
 echo "<script>$('#email-availability-status').prop('disabled',false);</script>";