File directory:
Html code:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> asynchronous Form Verification </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>
</Head>
<Body>
<Form name = 'form'>
<Input name = 'name' type = 'text' onblur = 'checkname (); '>
<Span id = 'show'> </span> <br/>
<Input type = 'submit 'name = 'submit' value = 'Submit'/>
</Form>
</Body>
</Html>
Php code:
Copy codeThe Code is as follows:
<? Php
// Connect to the server
$ Link = mysql_connect ('localhost', 'root', 'sanyun ');
If (! $ Link ){
Die ('Connection failed: '. mysql_error ());
}
// Connect to the database
Mysql_select_db ('expur', $ link );
// $ Name = $ _ GET ['name'];
Echo $ name;
$ SQL = "select name from user_info where name = '$ name '";
// Execute the query statement
$ Result = mysql_query ($ SQL );
If (mysql_num_rows ($ result )! = 0 ){
Echo "<font color = 'red'> the name is too popular. Change it. </font> ";
} Else {
Echo "<font color = 'blue'> success </font> ";
}
// Release the query result set
Mysql_free_result ($ result );
// Close the database connection
Mysql_close ($ link );
?>
Running result example: