Live Username Availability using PHP & jQuery

In this tutorial, We will learn how to implement username live check availability feature using PHP, jQuery and MySQL.We will send AJAX request to the server-side script(PHP) and get a response from the ajax request as a JSON object.

We will show a success/error message if the user name is available/exists or validation type error. It’s very useful when you are checking username availability on live form from the database.

This functionality is important when you are providing username availability on live enter of username.

live_Username_Availability

Step 1: Create a table to store the username into the database.

CREATE TABLE `users` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

INSERT INTO  `users` (  `id` ,  `username` ,  `email` ) 
VALUES (NULL ,  'phpflow',  '[email protected]'), 
(NULL ,  'parvez',  '[email protected]')

Step 2: Created a database connection file connection.php, to connect MySQL database to PHP.

<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}?>

Live Demo & Download Code

3 thoughts on “Live Username Availability using PHP & jQuery

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.