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>