Verify from the username User table in database my:
Checkusername.html:
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:
The 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 ");
}
?>