Php+ajax to detect if a user name or mail registration already exists instance tutorial, ajax instance Tutorial _php Tutorial

Source: Internet
Author: User

Php+ajax to detect if a user name or message registration is already present, an AJAX instance tutorial


Php+ajax detecting whether a user name or message registration already exists is an important feature that is common in the Forum or membership system. This paper simply describes the implementation of this function in the form of an example. The steps are as follows:

First, the PHP detection page

The check.php page code is as follows:

Second, the AJAX verification page

The Check.js page code is as follows:

var xmlhttp;function s_xmlhttprequest () {  if (window. ActiveXObject) {    xmlHttp = new ActiveXObject (' microsoft.xmlhttp ');  } else if (window. XMLHttpRequest) {    xmlHttp = new XMLHttpRequest ();}  } function funtest100 () {  var f = document.getelementsbytagname_r (' form ') [0].user.value;//gets the contents of the text box  S_ XMLHttpRequest ();  Xmlhttp.open ("Get", "jcfor.php?id=" +f,true);//Open request  Xmlhttp.onreadystatechange = byphp;//ready for execution  Xmlhttp.send (null);//Send}function byphp () {  //Judgment Status  if (xmlhttp.readystate==1) {//ajax status    document.getelementbyidx_x_x (' test100 '). InnerHTML = "Loading";  }  if (xmlhttp.readystate==4) {//ajax status    if (xmlhttp.status==200) {//server-side State      var bytest100 = Xmlhttp.responsetext;      alert (bytest100);      document.getelementbyidx_x_x (' test100 '). InnerHTML = bytest100;}}    }

Third, PHP verification page

The chkfor.php page code is as follows:

<?php if ($_get[id]) {    sleep (1);    $conn =mysql_connect (' localhost ', ' root ', ');    mysql_select_db (' Test ', $conn);    $sql = "SELECT * from ' user ' WHERE ' name ' = ' $_get[id] '";    $q =mysql_query ($sql);     if (Is_array (Mysql_fetch_row ($q))) {      echo "user name already exists";     } else{      echo "User name can be used";     }}  ? >

I hope that the examples described in this article will help you to develop PHP programs.


That friend has Php+ajax code to verify the user name

Documents include:

Userreg.html (Registration page)
Ajaxreg. JS (Ajax script and real-time verification of JS script)
Checkuserreg. PHP (a page that connects to the database and detects if the user name is registered)
Userreg.html (registration page) copy PHP content to clipboard
PHP Code:



<title>Untitled Document </title></title>

Related Article

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.