<!--
t.php Code
The code is as follows |
Copy Code |
? $title = isset ($_get[' title ')] $_get[' title ': '; if ($title) { $sql = ' Select id from filecontent where title= '. $title. '; $q = MySQL Tutorial _query ($sql) or Die (Mysql_error ()); if (mysql_num_rows ($q)) { Echo 1; } Else { echo 0; } } Else { echo 0; } ?> |
<!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> user registration to detect whether the user name exists Ajax + PHP code </title>
<script>
User registration to detect if the user name exists Ajax + PHP code
function Createxmlhttprequest () {//Create XMLHttpRequest Object
if (window.activexobject) {//ie
try {
return new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {
Return
}
}else if (window.xmlhttprequest) {//mozilla,firefox
try {
return new XMLHttpRequest ();
catch (e) {
Return
}
}
}
Function Getrenews (value) {//Keynote
var xmlhttp=createxmlhttprequest ();
var url = "t.php?action= Check&title= "+value+" &mt= "+math.random (300000);
if (value== "") {
return false;
}
if (XMLHTTP) {
& Nbsp;callback = Getreadystatehandler (XMLHTTP);
xmlhttp.onreadystatechange = callback;
xmlhttp.open ("Get", url,true);
xmlhttp.send (NULL);
}
}
//Return 0 is available on behalf of the user name, otherwise the prompt has already been registered.
Function Getreadystatehandler (XMLHTTP) {//server returns handler function
return functions () {
if ( Xmlhttp.readystate = 4) {
if (xmlhttp.status =) {
&NBSP
if (xmlhttp.responsetext==1) {
document.getelementbyid ("Checkid"). Innerhtml= "<font color= ' red ' > Sorry, the user name you entered is already registered! </font>
}else{
document.getelementbyid ("Checkid"). Innerhtml= "can register";
&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP
}
&NBSP}
}
</script>
<body>
Adds a onblur event to the input box, detects the user name when the user enters the user name, and prompts for it.
Enter user name <input name= "title" type= "text" id= "title" Size= "" onblur= "Getrenews (this.value);" ><span id= "Checkid" ></SPAN>
</body>