Skip to main content

Username Availability Check Using Jquery, PHP, Mysql, Ajax

When We try to Register for any website and On the Username Field We just type your desired Username and within Seconds Without Refreshing the Page the system Checks if the username Is Available or Not so today's my tutorial is based on the same functionality.
we have Following 4 Files in our Directory And Each file is going to perform its own function.

  1.  Index.php
  2. user.js 
  3. db.php
  4. username_check.php

    Following Function Will Be Performed When Our Username is being Checked

Download

  1. Username is fetched from index.php and send to the server for checking.
  2. if the username is taken then an error message will be shown
  3. else there will be a available message.
so lets start

First we have To create a index file. I am not using any stylesheet for this. its just an simple form without any formatting or styling.

so here is the code for index.php file


<!doctype html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title> Jquery Username Check Tutorial</title>
</head>
<body>
 <input id="username" type="text" /><span id="username_status"></span>
 
 <script type="text/javascript" src="js/jquery.js"></script>
 <script type="text/javascript" src="js/users.js"></script>
</body>
</html>

So it will show just an text field and and a span is there with an id "username_status" this span is for showing the status message.

Now lets write the user.js code. The jquery code is written below. This code will fetch the data from the index.php and send it to username_check.php and then will print the result to the page.


$('#username').keyup(function(){
var username = $(this).val();
$('#username_status').text('searching....');
if(username != '') {
$.post('username.php',{ username:username },function(data){
 $('#username_status').text(data);
});
}
else {
 $('#username_status').text('Nothing');
}
});

Now we here comes the username_check.php file which will perform the main functionality of this application.

<?php
if(isset($_POST['username']))
 {
  $username = mysql_real_escape_string($_POST['username']);
  echo $username;
 if(!empty($username))
   {
   $username_query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
   $username_result = mysql_result($username_query,0);
    if($username_result == 0)
     {
      echo 'Username available!';
     } else ($username_result ==1) {
      echo 'Sorry, That username is Taken!';
     }
    }
  ?>


And your are Done This will do everything you just have to make a database connection and this will start its working.

You can download whole script from the download link

Comments

Popular posts from this blog

Network Topologies (Tutorial-4)

Topology refers to the way in which the network of computers is connected. The choice of topology is dependent upon--- Type and number of equipment being used  Planned applications and rate of data transfers  Required response times  Cost Types of Network Topologies Physical Topology: Physical topology defines how devices are connected to the network through the actual cables that transmit data(physical structure of the network)  Logical Topology: Logical Topology (also referred to as Signal Topology) is a network computing term used to describe the arrangement of devices on a network and how they communicate with one another.

Cisco Hierarchical Model

Cisco Hierarchical Model Defined by Cisco to simplify the design, implementation, and maintenance of responsive, scalable, reliable, and cost-effective networks. The 3 layers are logical and not physical – there may be many devices in a single layer, or a single device may perform the functions of 2 layers, eg: core and distribution. The Cisco Hierarchical Model

Windows 7 transformation pack for xp

As the windows 7 launched after that there are lot of screenshot available on the internet, There developer designed the transformation packs for xp to make it better lo0king like windows 7. There are some transformation packs for your xp. Download Vienna 2.5 – Windows 7 Transformation Pack (Mirror) Downloa d HFN Windows 7 Transformation Pack Download Windows 7 Transformation pack – NSFormation (Mirror) Download Vienna Transformation Pack v1