Live Username Availability Check
Live Username Availability Check
Subscribe
To search, type a
Youhack.Me
Credits
The Background image in the textbox was generated from this Form Elements
Generator . The loading Image is taken from Preloaders .Other icons are taken
fromIconsPedia .
Database Structure
Jquery Code
This section contains the jquery Code that handles the Ajax request when the textbox loses focus .Based
on the server response , the appropriate icon is appended to the <span> with id=”availability_status”
.Almost every line of codes in commented below .
01 $(document).ready(function()//When the dom is ready
02 {
03 $("#username").change(function()
04 { //if theres a change in the username textbox
05
06 var username = $("#username").val();//Get the value in the username textbox
07 if(username.length > 3)//if the lenght greater than 3 characters
08 {
$("#availability_status").html('<img src="loader.gif"
09
align="absmiddle"> Checking availability...');
10 //Add a loading image in the span id="availability_status"
11
12 $.ajax({ //Make the Ajax Request
13 type: "POST",
14 url: "ajax_check_username.php", //file name
15 data: "username="+ username, //data
16 success: function(server_response){
17
18 $("#availability_status").ajaxComplete(function(event, request){
19
20 if(server_response == '0')//if ajax_check_username.php return value "0"
21 {
$("#availability_status").html('<img src="available.png"
22
align="absmiddle"> <font color="Green"> Available </font> ');
23 //add this image to the span with id "availability_status"
24 }
25 else if(server_response == '1')//if it returns "1"
26 {
$("#availability_status").html('<img src="not_available.png"
27
align="absmiddle"> <font color="red">Not Available </font>');
28 }
29
30 });
31 }
32
33 });
34
35 }
36 else
37 {
38
$("#availability_status").html('<font color="#cc0000">Username too
39
short</font>');
40 //if in case the username is less than or equal 3 characters only
41 }
42 return false;
43 });
44 });
PHP Code
As you have probably noticed , the file “ajax_check_username.php” is called via ajax
and the username is passed to the server . The code below query our database to check if the
username is already in our database or not . It will either return the value “0″ or “1″ .
01 include('database_connection.php');
02 //Include The Database Connection File
03
04 if(isset($_POST['username']))//If a username has been submitted
05 {
06 $username = mysql_real_escape_string($_POST['username']);//Some clean up :)
07
08 $check_for_username = mysql_query("SELECT userid FROM member WHERE
username='$username'");
09 //Query to check if username is available or not
10
11 if(mysql_num_rows($check_for_username))
12 {
13 echo '1';//If there is a record match in the Database - Not Available
14 }
15 else
16 {
17 echo '0';//No Record Found - Username is available
18 }
19 }
That’s all Folks ! Got a Comment ? Criticism?Share it with us below !
Related Posts
1. Create fancy contact form with CSS 3 and jQuery
2. Designing a form using pure CSS enhanced with Jquery
3. Building A registration System with Email verification in PHP
4. Creating a Fancy Search Feature with PHP,Mysql and Jquery
5. An Alternative to Pagination : Facebook and Twitter Style
Tagged as: Ajax, Jquery, Live Availability Check, PHP
2 trackbacks
Username Availability Check in Registration Form using Jquery/PHP Check body on me
May 4, 2010 at 4:01 am
Tweets that mention Username Availability Check in Registration Form using
Jquery/PHP -- Topsy.com
May 4, 2010 at 8:15 am
thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkk youuuuuuuuuuuuuuuuuuuu
Raihan
Email: [email protected]
Leave a Comment
Name *
E-mail *
Website
Submit
Email :
Subscribe
Recent Posts
Tag Cloud
Ajax Chart Components PHP Contact Form CSS Curl Database Size Delete using Jquery Downlaod file with
FlickRss Gallery
Recent Comments
WordPress Admin