1

Check Username Availability With jQuery In PHP And MySql

This is a script to Check Username availability with Jquery in PHP and MySql, after entering the username it will check in the database and displays a message depending on the result from the database, we are using simple jquery code to achieve this, first of all using jquery, we are reading the input value and then sending it a php page, it will search the database table, depending on the response it will display message.

Code for Check Username availability with Jquery in PHP and MySql

If you are following along from previous articles, you should have connect.php file to connect to database. And database table created with some records in it. If you haven’t follow these below articles.

  1. Simple User Registration Script in PHP and MySQL
  2. Simple Login Script in PHP and MySQL
  3. User Login with activation check using PHP and MySQL
  4. Send Forgotten Password by mail using PHP and MySQL
  5. Check Username Availability With jQuery In PHP And MySql

You can watch this video about username availability with jQuery in PHP & MySQL

Create a simple form with username, email, password fields. You can use this below form HTML code.

And add this below code, right after the username input div. This code is used to display loading image while typing username & to display messages like “username available” or “username not available”.

Then add the jQuery file inside head section the HTML code, you can use any latest version.

Add this jQuery code below jQuery CDN file. This code is used to send input fields value to check.php file (that we are going to create it) based on the id assigned to input field while typing (using keyup jQuery function).

Also while typing I’m displaying loading gif (you can use any loading animation image in square shape). After getting result from check.php, I’m hiding loading image & displaying message in #usernameResult id like “username available” or “username not available”.

Then create a new PHP file & save this as check.php. This file is used to check the username from database & displaying results in our main file under username field.

Fisrt of all include connect.php file

Then I’m execting PHP code, if the post super global has data.
Assigning username to a variable, using select sql query checking username exists in database or not.

If the select queries result is equal to one, that means a record exists in database with that specific username “username not available” message will be displayed. Else “username available” message will be displayed.

Complete Code of Check Username Availability With jQuery In PHP And MySql

If you have problem arranging above pieces of code, you can use this complete code.

If you want to learn other things you can read other posts – registration, login, user login with activation check, and sending forgotten password by email, Check Username Availability .

I hope this article helped you to learn user login using PHP and MySQL . To get latest news and updates follow us on twitter & facebook, subscribe to newsletter. If you have any feedback please let us know by using comment form.


check availability form in php mysql checking username and password on btn click through jquery php
Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 1 comments
Abhijt

thanks a lot I need this code

Reply

Leave a Reply: