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.
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(); }?>
Hi,
This code looks good but where is the database connection?
Thanks,
Ben
Hi Ben,
I had assumed , User has database connection layer.
Thank That’s what i want to learn
Download Link Not Working
fixed url issue