Aug 20, 2015

Ajax Username Validation with PHP and MySQL

Written by

Tutorial for ajax username validation using jquery and php to check if the username is available in the mysql database.


  • jQuery Library

Database and table

First create a database in mysql and create a table called members in it.

Insert some dummy values.


members table in mysql

HTML Markup

We need a text input box and a div to show the result, with suitable ids.


After including the jQuery library insert the above code inside of your head tag

We used a function called .blur()

Whenever the input box with the id of “username” looses its focus, the jQuery code will send an ajax request to validation.php.

For this tutorial, we’ve used GET method but you can use POST method as well.


Basically it sends the username to validation.php if it is not empty

We are trying to select the username from members table where the username is equal to the value entered in text box.

If the result returns one or more rows, then the username is not available otherwise it is availabe.

Article Tags:
· · · · · · · ·
Article Categories: