php注册审核显示

用户进行注册,管理员通过审核后,使用户通过审核

数据库建表

create database mydb;

use mydb;

create table User
(
    Uid int auto_increment primary key,
    Name varchar(50),
    Pwd varchar(50),
    Sex bit,
    Time date,
    IsOK bit
)
View Code

注册:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
<script src="../../jquery-1.11.2.min.js"></script>
</head>

<body>

<div>用户名:<input type="text" id="name" /></div>
<div>密码:<input type="text" id="pwd" /></div>
<div>性别:男<input type="radio" id="nan" name="sex" value="true" /><input type="radio"  name="sex" value="false" /></div>
<div>生日:<input type="text" id="birthday" /></div>
<div><input type="submit" value="注册" id="zc" /></div>       

</body>
<script type="text/javascript">
$(document).ready(function(e) {
    $("#zc").click(function(e) {
        var name = $("#name").val();
        var pwd = $("#pwd").val();
        var sex = $("#nan")[0].checked;
        var birthday = $("#birthday").val();
        
        $.ajax({
            url:"ZhuCeChuLi.php",
            data:{name:name,pwd:pwd,sex:sex,birthday:birthday},
            type:"POST",
            dataType:"TEXT",
            success: function(data)
            {
                if(data)
                {
                    alert("注册成功!");
                }
                else
                {
                    alert("注册失败!");
                }
            }
        });
    });
});
</script>
</html>
View Code

注册处理:

<?php


include("../../DBDAajax.php");


$name = $_POST["name"];
$pwd = $_POST["pwd"];
$sex = $_POST["sex"];
$birthday = $_POST["birthday"];


$db = new DBDAajax();
$sql = "insert into User values('','".$name."','".$pwd."','".$sex."','".$birthday."',false)";
$str = $db->Query($sql,0);
echo $str;
View Code

审核1.:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理</title>
<script src="../../jquery-1.11.2.min.js"></script>
</head>

<body>
<table width="100%" height="200px" bgcolor="#33CCCC" border="3px">
<tr>
<td>编号</td>
<td>用户名</td>
<td>密码</td>
<td>性别</td>
<td>生日</td>
<td>操作</td>
</tr>
<?php
include("../../DBDAajax.php");

$db = new DBDAajax();
$sql = "select * from User";
$result = $db->Query($sql);


for($i=0;$i<count($result);$i++)
{
    echo "<tr>";
$zhuangtai = $result[$i][5]?"<span style='80px; height:28px; background-color:green; color:white'>已通过</span>":"<a href='GuanLiChuLi.php?uid={$result[$i][0]}' onclick='return confirm("审核通过!")'>审核</a>";
        echo "<td>{$result[$i][0]}</td>
            <td>{$result[$i][1]}</td>
            <td>{$result[$i][2]}</td>
            <td>{$result[$i][3]}</td>
            <td>{$result[$i][4]}</td>
            <td>{$zhuangtai}</td>";
            
        
    
    echo "</tr>";
}


?>
</table>
</body>

</html>
View Code

审核2.:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>注册审核</h1>

<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
    <td>用户名</td>
    <td>姓名</td>
    <td>性别</td>
    <td>生日</td>
    <td>状态</td>
</tr>
<?php

    include("DBDA.php");
    $db = new DBDA();
    
    $sql = "select * from Users";
    
    $attr = $db->Query($sql);
    
    for($i=0; $i<count($attr);$i++)
    {
        
        echo "<tr>
        <td>{$attr[$i][0]}</td>
        <td>{$attr[$i][2]}</td>
        <td>{$attr[$i][3]}</td>
        <td>{$attr[$i][4]}</td>";
        
        if($attr[$i][6])
        {
            echo "<td><span style='background-color:green'>已通过</span></td>";
        }
        else
        {
            echo "<td><a href='shenhe.php?uid={$attr[$i][0]}'>审核</a></td>";
        }
        
        echo "</tr>";
    }

?>
</table>
</body>
</html>
View Code

审核处理:

<?php
include("../../DBDAajax.php");
$uid = $_GET["uid"];

$db = new DBDAajax();

$sql = "update User set IsOK = true where Uid = '".$uid."'";

$db->query($sql,0);


header("Location:GuanLi.php");
View Code

查询数据库类:

<?php

class DBDAajax
{
    public $host = "localhost";//服务器地址
    public $uid = "root";      //数据库的用户名
    public $pwd = "101213";   //数据库的密码
    
    
    //执行SQL语句返回相应结果的函数
    //sql是要执行的语句
    //$type是SQL语句的类型,0代表增删改,1代表查询
    //$db代表要操作的数据
    public function Query($sql,$type=1,$db="mydb")
    {
        //造连接对象
        $conn = new mysqli($this->host,$this->uid,$this->pwd,$db);
        
        //判断连接是否成功
        !mysqli_connect_error() or die("连接失败");
        
        //执行SQL语句db
        $result = $conn->query($sql);
        
        //判断SQL语句类型
        if($type == 1)
        {
            //如果是查询语句返回结果是二维数组
            return $result->fetch_all();
        }
        else
        {
            //如果是其他语句返回true或false
            return $result;
        }
        
    }
    
    //Ajax调用返回字符串
    //ajax调用的方法
    //sql是要执行的语句
    //$type是SQL语句的类型,0代表增删改,1代表查询
    //$db代表要操作的数据
    public function Ajax($sql,$type=1,$db="lian1")     
    {
        //造连接对象
        $conn = new mysqli($this->host,$this->uid,$this->pwd,$db);
        
        //判断连接是否成功
        !mysqli_connect_error() or die("连接失败");
        
        //执行SQL语句
        $result = $conn->query($sql);
        
        
            
            //将数组拼成字符串
            //如果是查询语句拼成字符串
            $str = "";
            if($type==1)
            {
            $attr = $result->fetch_all();
            for($i=0;$i<count($attr);$i++)
            {
                    for($j=0;$j<count($attr[$i]);$j++)
                {
                    $str = $str.$attr[$i][$j];
                    $str = $str."^";
                }
                $str = substr($str,0,strlen($str)-1);    
                $str = $str."|";
            }
                $str = substr($str,0,strlen($str)-1);    
                return $str."<br>";
            
            }
            else
            {
                return $result;
            }
    }
    

//Ajax调用返回JSON
public function JsonQuery($sql,$type=1,$db="lian1")
{
    //定义数据源
    $dsn = "mysql:dbname={$db};host={$this->host}";
    //造pdo对象
    $pdo = new PDO($dsn,"{$this->uid}","{$this->pwd}");
    
    //准备执行SQL语句
    $st = $pdo->prepare($sql);
    
    //执行预处理语句
    if($st->execute())
    {
        if($type==1)
        {
            $attr = $st->fetchAll(PDO::FETCH_ASSOC);//用pdo返回所有数据的关联数组
            return json_encode($attr);//用这个函数转换为JSON数据
        }
        else
        {
            if($st)
            {
                return "OK";
            }
            else
            {
                return "ON";
            }
        }
    }
    else
    {
        echo "执行失败!";
    }
}

            
}
View Code
原文地址:https://www.cnblogs.com/sjxx/p/5405566.html