Verify from the Username user table in the database my:
Checkusername.html:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<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>
check_it.php:
Copy Code code 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");
}
?>