Typical PHP project Case study: (1) blog Management System 4. Typical PHP project Case Study-(1) blog Management System 4 This article uses Ajax to implement a page without refreshing to verify whether the user name exists. VII. Registration page implementation 1. Registration page design a typical php project in register. PHP-(1) blog Management System 4
This document uses Ajax to check whether the user name exists without refreshing the page. VII. Registration page implementation 1. Registration page design part of register. php code:
2. javascript function implementation called after the input box loses focus: fun. js:
Function chkUserName () {var c = document. getElementById ('txt _ regname'); var d = c. value; var id; if (d = "") {document. getElementById ('l1 '). innerText = "enter the user name"; document. getElementById ('ll1 '). innerText = "";} else {var xmlObj; xmlObj = new XMLHttpRequest (); xmlObj. open ('post', 'chk. php? D = '+ d, true); xmlObj. onreadystatechange = callBackFun; xmlObj. send (null); function callBackFun () {if (xmlObj. readyState = 4 & xmlObj. status = 200) {if (xmlObj. responseText = 'y') {document. getElementById ('l1 '). innerText = "×"; document. getElementById ('ll1 '). innerText = "";} else {document. getElementById ('l1 '). innerText = ""; document. getElementById ('ll1 '). innerText = "√" ;}}}} function chkRealName () {var c = document. getElementById ('txt _ regrealname '); var d = c. value; if (d = "") {document. getElementById ('l4 '). innerText = "enter your real name"; document. getElementById ('ll4 '). innerText = "";} else {document. getElementById ('l4 '). innerText = ""; document. getElementById ('ll4 '). innerText = "√" ;}} function chkPwd () {var p = document. getElementById ('txt _ regpwd '). value; var c = document. getElementById ('ll1 '). innerText; if (c = "√") {if (p = "") {document. getElementById ('l2 '). innerText = "enter password";} else if (p. length <3) {document. getElementById ('l2 '). innerText = "×"; document. getElementById ('ll2 '). innerText = "";} else {document. getElementById ('l2 '). innerText = ""; document. getElementById ('ll2 '). innerText = "√" ;}}function chkRePwd () {var p = document. getElementById ('txt _ regpwd '). value; var rp = document. getElementById ('txt _ regpwd2 '). value; var c = document. getElementById ('ll2 '). innerText; if (c = "√") {if (p = rp) {document. getElementById ('ll3 '). innerText = "√"; document. getElementById ('l3 '). innerText = "";} else {document. getElementById ('ll3 '). innerText = ""; document. getElementById ('l3 '). innerText = "× inconsistent passwords" ;}} function chkBirth () {var c = document. getElementById ('birth'); var d = c. value; if (d = "") {document. getElementById ('l6 '). innerText = "enter the date of birth"; document. getElementById ('ll6 '). innerText = "";} else {document. getElementById ('l6 '). innerText = ""; document. getElementById ('ll6 '). innerText = "√" ;}} function chkEmail () {var e = document. getElementById ('txt _ regemail '). value; if (e = "") {document. getElementById ('l5 '). innerText = "enter your email address"; document. getElementById ('ll5 '). innerText = "";} else {document. getElementById ('l5 '). innerText = ""; document. getElementById ('ll5 '). innerText = "√ ";}}
3. the chk. php file used by Ajax to verify the user name :'
execute_dql($sql); $s = $res->fetch_assoc(); if(count($s)!=0){ echo 'y'; }else{ echo 'n'; }
4. After registration, add the user to the database registerdeal. php.
Execute_dql ($ SQL); $ result = $ res-> fetch_assoc (); if (count ($ result )! = 0) {echo ("script" alert ('The user name has been registered! '); History. go (-1); script "); exit () ;}$ _ SESSION ['username'] =$ _ POST ['txt _ regname']; $ regname = $ _ POST ['txt _ regname']; $ regrealname = $ _ POST ['txt _ regrealname']; $ regpwd =$ _ POST ['txt _ regpwd ']; $ regbirthday =$ _ POST ['txt _ birthday']; $ regemail =$ _ POST ['txt _ regemail']; $ regcity =$ _ POST ['txt _ province ']. $ _ POST ['txt _ City']; $ regico =$ _ POST ['txt _ ico ']; $ regsex =$ _ POST ['txt _ regsex']; $ regqq =$ _ POST ['txt _ regqq']; $ reghomepage =_ _ POST ['Txt _ reghomepage']; $ regsign = $ _ POST ['txt _ regsign']; $ regintroduce = $ _ POST ['txt _ regintroduce ']; $ ip = getenv (REMOTE_ADDR); $ SQL = "Insert Into tb_user (regname, regrealname, regpwd, region, regemail, regcity, regico, regsex, regqq, reghomepage, regsign, regintroduce, ip, fig )". "Values ('$ regname',' $ regrealname ',' $ regpwd ',' $ regbirthday ',' $ regemail ',' $ regcity ',' $ regico ', '$ regsex', '$ regqq',' $ reghomepage ',' $ regsign ',' $ Regintroduce ',' $ IP', 0) "; $ INS = $ sqlHelper-> execute_dml ($ SQL ); echo "script" alert ('User registration successful! '); Script "; echo" script "window. location = 'index. php'; script";?>
So Far
, User registration has been implemented.
Blog-(1) blog Management System 4 This article uses Ajax to implement a page without refreshing and verify whether the user name exists. VII. Registration page implementation 1. Registration page design register. php...