I have a form to filled out by user. Its user registration form. I want that when user fill username text,my form should search for user name whether it exist or not.If it exist then username text field should get focus.My database table name is users and it contains column named as id,username,password,status.
Here is my code.
<form name="user" action="#" method="post">
<label>Username</label>
<input type="text" maxlength="25" name="username" />
/*here i want to check from my db table weather username exists or not*/
<label>Password</label>
<input type="password" maxlength="25" name="password" />
<input type="submit" value="Submit" />
</form>
I can do it when user submits the form.But my requirement is to check value with out submitting form and username should get focus.
and in php I have following code
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$username = $_REQUEST['username'];
$query=mysql_query("SELECT * from user where name='$username'");
$row=mysql_num_rows($query);
if($row==1){
echo "true";
} else {
echo "false";
}
?>
Html Form
Js
write your table user name checking in
check_username.php, the response from this php is count of rows with the provided username,something like below