User registration to detect if the user name exists Ajax + PHP code

Source: Internet
Author: User
Tags mysql tutorial

<!--
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.