Ajax Username Validation with PHP and MySQL

21:14:00 0 Comments

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

Requirements

Database and table

First create a database in mysql and create a table called members in it.
Insert some dummy values.

Example

members table in mysql

HTML Markup

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

jQuery

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.

validation.php

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.
Now give a nice style to the classes green and red with the help of CSS

That’s it. Keep sharing the post and keep scrolled with us for more updates.

0 comments :