File directory:
HTML code:
Copy Code code as follows:
<title> Asynchronous Form Validation </title>
<script type= ' text/javascript ' src= ' jquery.js ' ></script>
<script>
function CheckName () {
$ ("Input[name= ' name ')"). Val ()
$.ajax ({
Type: "Get",
URL: ' index.php ',
Data: "Name=" +$ ("input[name= ' name ')"). Val (),
Success:function (msg) {
$ ("#show"). Append (msg);
}
});
}
</script>
<body>
<form name= ' form ' >
<input name= ' name ' type= ' text ' onblur= ' checkname (); ' >
<span id= ' show ' ></span><br/>
<input type= ' submission ' name= ' submit ' value= ' submitted '/>
</form>
</body>
PHP Code:
Copy Code code as follows:
<?php
To connect to the server
$link =mysql_connect (' localhost ', ' root ', ' Sanyue ');
if (! $link) {
Die (' Connection failed: '. mysql_error ());
}
To connect to the database
mysql_select_db (' Excour ', $link);
$name =$_get[' name '];
Echo $name;
$sql = "SELECT name from User_info where name= ' $name '";
Executing query statements
$result =mysql_query ($sql);
if (mysql_num_rows ($result)!= 0) {
echo "<font color= ' red ' > name too popular, change a bar </font>";
}else{
echo "<font color= ' Blue ' > Success </font>";
}
To release the query result set
Mysql_free_result ($result);
To close a database connection
Mysql_close ($link);
?>
Run Results Sample: