PHP Classic Project Case-(a) blog management System 4

Source: Internet
Author: User

This article uses Ajax to implement a page without a refresh to verify that the user name exists. Seven, the registration page implementation1. Registration page Designregister.php part of the code:
<tr> <!--registration Form-&LT;TD colspan=3 valign= "Baseline" style= "Background-image:url (images/bg.jpg); Vertical-align:middle; height:450px; Text-align:center "><br> <form name=" MyForm "action=" register_deal.php "method=" POST "> &L T;table width= "85%" border= "1" align=center cellpadding=3 cellspacing=2 bordercolor= "#FFFFFF" bgcolor= "#FFFFFF" class= I_table> <tr align= "left" bgcolor= "#EFF7DE" > <td height=22 colspan=2 bgcolor= "#EFF7D             E "Class=right_head><span class=" tableborder_ltr "> Required content </span></td> </tr>                <tr bgcolor= "#FFFFFF" > <td width=22% align= "right" valign=middle class= ' f_one ' > user name </td> &LT;TD width=78% align= "left" class= ' F_one ' ><input name= ' txt_regname ' type=text id= ' Txt_regname ' val Ue= ' size=20 maxlength=14 onblur= "Javascript:chkusername ();" /> <label id= "L1" >*</label><label id= "Ll1" class= "Label2" ></label> </td> </tr> <t R bgcolor= "#FFFFFF" > <td align= "right" Valign=middle > real name </td> <td align= " Left "> <input name= ' txt_regrealname ' type= ' text ' id=" txt_regrealname "size= '" maxlength= ' "onblur=" Javascript:chkrealname () "/> <label id=" L4 ">*</label><label id=" Ll4 "class=" Label2 "></label></td> </tr> <tr> <tr bgcolor=" #FFFFFF "&G               T &LT;TD align= "right" valign=middle > Password </td> <td align= "left" > <input name= ' txt_regpwd ' ty Pe= ' password ' id= "txt_regpwd" size=20 maxlength=75 onblur= "javascript:chkpwd ();" /> no less than 3 digits such as English letters or numbers <label id= "L2" >*</label><label id= "Ll2" class= "Label2" &GT;&LT;/LABEL&GT;&L t;/td> </tr> <tr bgcolor="#FFFFFF" > <td align= "right" valign=middle> Confirm password </td> <td align= "left" > <input name= ' txt_regpwd2 ' type= ' password ' id= "txt_regpwd2" size=20 maxlength=75 onblur= "javascript:chkrepwd ()"             > <label id= "L3" >*</label><label id= "Ll3" class= "Label2" ></label></td>               </tr> <tr bgcolor= "#FFFFFF" > <td align= "Right" > Date of birth </td>  &LT;TD align= "Left" > <span class= "Word_grey" > <input name= "txt_birthday" type= "text" Id= "Birth" onblur= "Javascript:chkbirth ()" > (date Format: YYYY-MM-DD) <label id= "L6" >*</label><lab               El id= "ll6" class= "Label2" ></label></td> </tr> <tr bgcolor= "#FFFFFF" > &LT;TD align= "Right" valign=middle> email</td> <td align= "left" > <input nam E=txt_regemail type=text id= "Txt_Regemail "value=" size=35 maxlength=75 onblur= "javascript:chremail ()"/> <font color= ' #000000 ' > Open mailbox <label id= "L5" >*</label><label id= "ll5" class= "Label2" ></label></td> </tr&gt             ;                <tr bgcolor= "#FFFFFF" > <td align= "Right" > City </td> <td align= "left" > <select name= "txt_province" id= "txt_province" onchange= "javascript:initcity ();" > <script>creatprovince ();</script> </select> <s             Elect name= "txt_city" id= "txt_city" > </select> <font color= "Red" >*</font> </td> </tr> <tr bgcolor= "#FFFFFF" > <td align= "right" valign=middle class= ' F_one ' > select Avatar:</td> <td align= "left" class= ' F_one ' ><table width= "106" cellpadding= "0" cells pacing= "0" > <tr> <td width= "Ten" height= "></td> <td width=" ></td> <td width= "5                   3 "rowspan=" 2 "align=" center "><font color=red>*</font></td> </tr>  <tr> <td> </td> <td> <select name= "Txt_ico" Size= "1" id= "Txt_ico" onchange= "Javascript:showlogo ()" > <option value= "0.gif" selected> head                        Like 1 <option value= "1.gif" > Avatar 2 <option value= "2.gif" > Avatar 3 <option value= "3.gif" > Avatar 4</option> <option value= "4.gif" > Avatar 5</o ption> <option value= "5.gif" > Avatar 6</option> </select> &lt                ;/td>   </tr> </table></td> </tr> <tr align= "left" bgcolor= "#E Ff7de "> <td height=22 colspan=2 class=right_head><span class=" tableborder_ltr "> Optional content </span& gt;</td> </tr> <tr bgcolor= "#FFFFFF" > <td align= "right" class= ' F_one ' > Gender </td> <td align= "left" class= ' F_one ' > <select name=txt_regsex id= "Txt_regsex"                   ; <option value=1> men </OPTION> <option value=2> Women </OPTION> <opti On value=0 selected> privacy </OPTION> </select></td> </tr> < TR bgcolor= "#FFFFFF" > <td align= "right" class= ' F_one ' >QQ</td> <td align= "Lef          T "class= ' f_one ' ><input name= ' txt_regqq ' type=text id=" txt_regqq "value=" size=20 maxlength=14></td>   </tr> <tr bgcolor= "#FFFFFF" > <td align= "right" class= ' F_one ' > personal home &LT;/TD&G               T &LT;TD align= "left" class= ' F_one ' > <input name= ' txt_reghomepage ' type=text id= ' txt_reghomepage ' value= ' size=40 maxlength=75></td> </tr> <tr bgcolor= "#FFFFFF" > <td align= "R ight "Valign=middle class= ' f_one ' > personalized signature </td> <td align=" left "class= ' F_one ' ><textarea name = ' txt_regsign ' cols=50 rows= ' 4 ' id= "txt_regsign" ></textarea></td> </tr> <t R bgcolor= "#FFFFFF" > <td align= "right" class= ' F_one ' > Self introduction </td> <td align= "L EFT "class= ' F_one ' ><textarea name=txt_regintroduce cols=50 rows=4 id=" Txt_regintroduce "></textarea> </td> </tr> </table> <br> <input type= ' Submit ' name = ' Regsubmit ' value= ' Submit ' class= "Btn_grey" onclick= "return Check ()" >   <input name= "reset" type= "reset" class= "Btn_grey"  Value= "Refill" > </form> </td> </tr>

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= "Please enter user name";d Ocument.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= "x";d Ocument.getelementbyid (' ll1 '). InnerText ="";} Else{document.getelementbyid (' L1 '). innertext= "";d Ocument.getelementbyid (' ll1 '). innertext= "√";}}}} function Chkrealname () {var c = document.getElementById (' txt_regrealname '); var d = c.value;if (d== "") { document.getElementById (' L4 '). innertext= "Please enter your real name";d Ocument.getelementbyid (' Ll4 '). innertext= "";} Else{document.getelementbyid (' L4 '). innertext= "";d Ocument.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=" Please enter your password ";} else if (p.length<3) {document.getElementById (' L2 '). innertext= "x";d Ocument.getelementbyid (' ll2 '). innertext= "";    Else{document.getelementbyid (' L2 '). innertext= "";d Ocument.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= "√";d Ocument.getelementbyid (' L3 '). innertext= "";} Else{document.getelementbyid (' Ll3 '). innertext= "";d Ocument.getelementbyid (' L3 '). innertext= "x password Inconsistent";}} function Chkbirth () {var c = document.getElementById (' birth '); var d = c.value;if (d== "") {document.getElementById (' L6 '). innertext= "Please enter the date of birth";d Ocument.getelementbyid (' ll6 '). innertext= "";} Else{document.getelementbyid (' L6 '). innertext= "";d Ocument.getelementbyid (' ll6 '). innertext= "√";}} function Chkemail () {var e = document.getElementById (' Txt_regemail '). Value;if (e== "") {document.getElementById (' L5 '). innertext= "Please enter the mailbox";d Ocument.getelementbyid (' ll5 '). innertext= "";} Else{document.getelementbyid (' L5 '). innertext= "";d Ocument.getelementbyid (' ll5 '). innertext= "√";}}

3, the AJAX authentication user name uses the processing file chk.php: '
<?php    require_once ' conn/sqlhelper.class.php ';    $chk = $_request[' d '];    $sqlHelper = new SqlHelper ();    $sql = "SELECT * from Tb_user where regname= ' $chk ';";    $res = $sqlHelper->execute_dql ($sql);    $s = $res->fetch_assoc ();    if (count ($s)!=0) {        echo ' y ';    } else{        Echo ' n ';    }

4. Add the user to the database after registering registerdeal.php
<?phpsession_start (); include "conn/sqlhelper.class.php"; $sqlHelper = new SqlHelper (); $UserName =$_post[' Txt_ Regname ']; $sql = "SELECT * from tb_user where regname = ' $UserName '"; $res = $sqlHelper->execute_dql ($sql); $result =$ RES-&GT;FETCH_ASSOC (); if (count ($result)!=0) {echo ("<script>alert (' username already 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, Regbirthday,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 , the user registration has been implemented.

PHP Classic Project Case-(a) blog management System 4

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.