Check username availability PHP. Username and password is widely used in any modern web site right now. Username is unique, it must be different with others. Therefore, we as developers have to write a code to check whether a username is already been taken or not yet.
I wrote simple code to do live check username availability using jQuery and Ajax in PHP.Live means you don’t need to click the submit button then send username into another code that returns availability of username. You can customize the code to better suit your need.
Table Structure
1 2 3 4 5 6 |
+----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+-------+ | username | varchar(50) | NO | PRI | NULL | | | password | varchar(32) | NO | | NULL | | +----------+-------------+------+-----+---------+-------+ |
username.php
this is the html form and jQuery function to perform check username availability PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
<html> <head> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <!-- <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script> --> <script type="text/javascript"> $(document).ready(function(){ $("#username").change(function(){ $("#message").html("<img src='ajax-loader.gif' /> checking..."); var username=$("#username").val(); $.ajax({ type:"post", url:"check.php", data:"username="+username, success:function(data){ if(data==0){ $("#message").html("<img src='tick.png' /> Username available"); } else{ $("#message").html("<img src='cross.png' /> Username already taken"); } } }); }); }); </script> </head> <body> <table> <tr> <td>Username</td> <td>:</td> <td><input type="text" name="username" id="username"/><td> <td id="message"><td> </tr> <tr> <td>Password</td> <td>:</td> <td><input type="text" name="password" id="password" /><td> </tr> </table> </body> </html> |
check.php
This code will return a value which is 0 to indicate that username is available or 1 indicate that username can’t be used. We use this simple logic, 0 or 1 to check username availability PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php mysql_connect("localhost","root",""); mysql_select_db("php_usernamelivecheck"); $username=$_POST["username"]; $query=mysql_query("SELECT * from user where username='$username' "); $find=mysql_num_rows($query); echo $find; ?> |
Try to type some letters in the username text field and then change focus of the cursor on the password field. Checking is on the way
If the username you wrote is not yet registered, the system will tell you that it is available to be used.
However if you pick up username that have been registered the system will tell you too
thanks. my problem is solved
You might be able to acquire exercising courses that decrease the employer&s insurance fees, as a result lowering your own premiums. What does this suggest? First, it means the fuel efficiency is great; this diesel motor features a capacity of around 38 liters, [url=http://www.shoptheducks.com/saku-koivu-jersey-eh-88/]Saku Koivu Jersey[/url], and gets about 14kmpl.Make use of the wellbeing advantages offered to you against your own medical health insurance business. If it doesnt, then go on to the next trick. For instance, apart from credit rating card accounts, possessing a home finance loan, an vehicle loan and other credit score in your account shows your capability in how you deal with your obligations as a borrower.With less bovine collagen, its more challenging for skin to recover following the injury that acne breakouts could trigger.[url=http://www.shoptheducks.com/corey-perry-jersey-qh-67/]www.shoptheducks.com/corey-perry-jersey-qh-67/[/url].[url=http://www.shoptheducks.com/scott-niedermayer-jersey-uk-21/]Scott Niedermayer Jersey[/url].Welcome to the place, there are several agents useful life, as in the great buying and selling of the house. Taking into consideration the value of your time and the climb up the learning curve, it frequently makes the most sense to simply let trained professionals perform the necessary repairs for you. Numerous students gain weight their first year in institution. Tolerate leather straps out of direct sunlight to avoid fading.Disregarding personal hygiene get a drastic consequences as it is presentation that runs the show as we speak But still this sad to find that many people forgot that problems which include body odor are actually pretty easy to handle having simple solutions like using a deodorant or another perfume like calvin klein. Velcro-strapped sandals are great for tender little legs that want to own wet summertime fun. Never ever reuse answer– discard this out after each usage– and also if you get a bottle of solution that is actually started past the expiration time, discard this.