在日常上网中,经常会遇到注册会员、登陆网页,并且管理员对注册信息审核
第一:注册表单页面
<body> <h1>注册</h1> <form action="zcchuli.php" method="post"> <div>用户名:<input type="text" name="uid"/></div> <div>密 码:<input type="text" name="pwd"/></div> <div>姓 名:<input type="text" name="name"/></div> <div>生 日:<input type="text" name="birthday"/></div> <div>性 别:<input type="radio" name="sex" value="1"/>男 <input type="radio" name="sex" value="0"/>女</div> <div><input type="submit" name="注册"/></div> </form> </body>
第二:将提交的表单添加到数据库的后台代码
<?php $uid=$_POST["uid"]; $pwd=$_POST["pwd"]; $name=$_POST["name"]; $birthday=$_POST["birthday"]; $sex=$_POST["sex"]; include("DBDA.class.php"); $db=new DBDA(); $sql="insert into user values('{$uid}','{$pwd}','{$name}','{$birthday}',{$sex},false)"; $re=$db->Query($sql,1); if($re) { header("location:zhuce.php"); }
第三:登陆表单页面(已通过审核的会员)
<body> <h1>登陆</h1> <form action="dlchuli.php" method="post"> <div>用户名:<input type="text" name="uid"/></div> <div>密 码:<input type="text" name="pwd"/></div> <div><input type="submit" value="登陆"/></div> </form> </body> </html>
第四:将登陆表单提交后台进行验证
session_start(); $uid=$_POST["uid"]; $pwd=$_POST["pwd"]; include("DBDA.class.php"); $db=new DBDA(); $sql="select count(*) from user where uid='{$uid}' and pwd='{$pwd}' and isOK=true"; $re=$db->StrQuery($sql); if($re==1) { $_SESSION["uid"]=$uid; header("location:main.php"); } else { header("location:login.php"); }
第五:审核页面显示
<body> <h1>审核</h1> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr align="center"> <td>姓名</td> <td>生日</td> <td>性别</td> <td>状态</td> </tr> <?php session_start(); if(empty($_SESSION["uid"])) { header("location:login.php"); } include("DBDA.class.php"); $db=new DBDA(); $sql="select * from user"; $attr=$db->Query($sql); foreach($attr as $v) { //处理状态 if($v[5]) { $zt="<span style='background-color:green;color:white'>已通过</span><a href='chexiao.php?uid={$v[0]}'>撤销</a>"; } else { $zt="<a href='shenhe.php?uid={$v[0]}'>审核</a>"; } echo "<tr align='center'> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td>{$zt}</td> </tr>"; } ?> </table> </body> </html>
第六:点击“审核”后台运行代码
<?php $uid=$_GET["uid"]; include("DBDA.class.php"); $db=new DBDA(); $sql="update user set isok=true where uid='{$uid}'"; $re=$db->Query($sql,1); if($re) { header("location:main.php"); } else { echo "审核失败!"; }
第七:点击“撤销”后台运行的代码
<?php $uid=$_GET["uid"]; include("DBDA.class.php"); $db=new DBDA(); $sql="update user set isok=false where uid='{$uid}'"; $re=$db->Query($sql,1); if($re) { header("location:main.php"); } else { echo "撤销失败!"; }