Verify from the username User table in database my:
Checkusername.html:
CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Script language = "JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
Function send_request (URL, data ){
Createxmlhttprequest ();
XMLHTTP. Open ("Post", URL, true );
XMLHTTP. onreadystatechange = check_lll;
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHTTP. Send ("username =" + data );
}
Function check_lll (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
Alert (XMLHTTP. responsetext );
}
}
}
Function check_username (){
VaR F = Document. form1;
VaR username = f. username. value;
If (username = ""){
Alert ("null ");
Return false;
}
Else {
Send_request ("check_it.php", username );
}
}
</SCRIPT>
<Body>
<Form ID = "form1" name = "form1" method = "Post" Action = "">
<P> </P> <p>
Name: <input type = "text" name = "username"/>
</P>
<Input type = "button" value = "Check it" onclick = "check_username ()"/>
<P> </P>
<P> </P>
</Form>
</Body>
</Html>
Check_it.php:Copy codeThe Code is as follows: <? PHP
$ Username = $ _ post ["username"];
$ Conn = mysql_connect ("localhost: 3306", "root", "123 ");
Mysql_select_db ("my", $ conn );
$ SQL = "select * from username where username = '$ username '";
$ Result = mysql_query ($ SQL, $ conn );
$ Num = mysql_fetch_array ($ result );
If ($ num> 0 ){
Printf ("can't use ");
}
Else {
Printf ("it can use ");
}
?>