username availbility checking or email uniqueness checking in php with ajax

    Hi guys! In this post i will show you how you can check the uniqueness of the email using ajax in php you can also use this video to check the username availability before user submits the form. We will use bootstrap to create the UI for this mini project the html code is given below :

    In the above code in line#59 i have used the onblur event will call a function called isUnique function(defined in line#16-21) and passes it the current value of the email input field u. The isUnique function will make an ajax request to the process.php and passes it the email as the parameter of the post request. Below is code for process.php:

    In the above code on line#3 we are checking if the post request is made using the $_POST superglobal. Then we are creating the mysqli connection object and storing the email from $_POST array to $email variable. After that we are creating the and executing the query and storing the result of the query in the result variable(line#11). Then in the end we are checking if database returned any row and if it is that means email entered by the user is not unique so we are displaying an error message saying this email is already taken. This error message is than returned to the isUnique function which displays it. This code can also be used to check the username availablity. You can also watch the video below :

    Click the button below to download source code
    Download Source

    Drop your questions and suggesions in the comments. Until next time Happy Coding 🙂

6 thoughts on “username availbility checking or email uniqueness checking in php with ajax

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge