php链接数据库 批量删除 和 注册审核

理解 :  hiden   value    session   name="a[]"

        1.  form  表单上传的 value=" "值  可以随意赋值   包括 该条数据  的 任何内容  ;

         2.(熟练 应用)form  表单  对  type="hiden"  属性的 应用    

(【下面 两个name 名  都为数组形式  上传】应用于需要提交到数据库 但是不想让客户看到的数据 ,这部分数据 可以 传值 用于辅助 后面 数据库 信息的提取, 比如  在  修改购物车  采购数量的信息 text 属性   如果不用   隐藏属性   提交只能提交 修改后的  text 的 value值 这样无法  找到  对应的  数据库位置 ; 再添加一个   隐藏框  隐藏的值  可以  是 当前这条信息的  主键  和  text  一起提交  根据 相同索引实现 一一对应  最终实现  数据库修改)

          3. session 属性的应用   :session  只要赋值一次   (并且 运行【如果关闭全部浏览器 默认  清掉 session 再次打开 如果  没有 打开  session命名 的界面   则表示  session  没有设定 ,只要打开一次就表示 session  已经设定了  】)  所有相关联的 表单都能获取到     ;  同理  cookie

         session   控制  打开页面  必须走   登录界面

          5.审核通过验证: 在注册界面多加了一个  隐藏 框 (hiden) 默认为1(可以为随便一个值)(和用户信息一起提交)

                                      只要不为1 就是审核 通过  (管理者通过这个 控制是否通过)

           6.批量删除:  使用 checkbox  标签     value值 变为 指定 要删除对象的   主键 (只要不重复的 都可以 ) name 以数组形式 书写  (提交数组)

                                全选按钮  使用 JS语言实现  (不想要提交(全选键)的信息   不要 设置name  就可以了)

---------------例题-----------------------------------------

精髓就是(跳转界面)   1.两个(或多个)界面来回跳转   2.传值    3.取值

壹.注册审核

1.注册

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9 <h1>审核页面</h1>
10 
11 <table width="100%" border="1" cellpadding="0" cellspacing="0">
12 
13     <tr>
14         <th>用户名</th>
15         <th>密码</th>
16         <th>姓名</th>
17         <th>性别</th>
18         <th>生日</th>
19         <th>状态</th>
20     </tr>
21     
22     <?php
23     include("../fengzhuang/DBDA.class.php");
24     $db = new DBDA();
25     
26     $sql = "select * from users";
27     $attr = $db->Query($sql);
28     foreach($attr as $v)
29     {
30         $zt = $v[5];
31         $str = "";
32         if($zt)
33         {
34             $str = "<span style=' color:green'>已通过</span><a href='bohui.php?uid={$v[0]}'>驳回</a>";
35         }
36         else
37         {
38             $str = "<a href='tongguo.php?uid={$v[0]}'>通过</a>";
39         }
40         
41         echo "<tr>
42         <td>{$v[0]}</td>
43         <td>{$v[1]}</td>
44         <td>{$v[2]}</td>
45         <td>{$v[3]}</td>
46         <td>{$v[4]}</td>
47         <td>{$str}</td>
48     </tr>";
49     }
50     
51     ?>
52 
53 
54 </table>
55 
56 </body>
57 </html>
zhuce.php

2.注册处理

 1 <?php
 2 $uid = $_POST["uid"];
 3 $pwd = $_POST["pwd"];
 4 $name = $_POST["name"];
 5 $sex = $_POST["sex"];
 6 $birthday = $_POST["birthday"];
 7 
 8 include("../fengzhuang/DBDA.class.php");
 9 $db = new DBDA();
10 
11 $sql = "insert into users values('{$uid}','{$pwd}','{$name}',{$sex},'{$birthday}',0,'')";
12 
13 $db->Query($sql,0);
14 
15 header("location:login.php");
zhucechul.php

3.登录

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9 <form action="loginchuli.php" method="post">
10     <div>用户名:<input type="text" name="uid" /></div>
11     <div>密码:<input type="password" name="pwd" /></div>
12     <input type="submit" value="登录" />
13 </form>
14 </body>
15 </html>
login.php

4.登录处理

 1 <?php
 2 $uid = $_POST["uid"];
 3 $pwd = $_POST["pwd"];
 4 
 5 include("../fengzhuang/DBDA.class.php");
 6 $db = new DBDA();
 7 
 8 $sql = "select pwd from users where uid='{$uid}'";
 9 
10 $attr = $db->Query($sql);
11 
12 if(!empty($pwd) && !empty($attr) && $attr[0][0] == $pwd)
13 {
14     //密码正确,判断状态
15     $szt = "select isok from users where uid='{$uid}'";
16     $azt = $db->Query($szt);
17     if($azt[0][0])
18     { 
19         echo "可以登录";
20     }
21     else
22     {
23         echo "未通过审核!";
24     }
25 }
26 else
27 {
28     //密码错误
29     echo "密码不对";
30 }
dengluchuli.php

5.审核界面

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9 <h1>审核页面</h1>
10 
11 <table width="100%" border="1" cellpadding="0" cellspacing="0">
12 
13     <tr>
14         <th>用户名</th>
15         <th>密码</th>
16         <th>姓名</th>
17         <th>性别</th>
18         <th>生日</th>
19         <th>状态</th>
20     </tr>
21     
22     <?php
23     include("../fengzhuang/DBDA.class.php");
24     $db = new DBDA();
25     
26     $sql = "select * from users";
27     $attr = $db->Query($sql);
28     foreach($attr as $v)
29     {
30         $zt = $v[5];
31         $str = "";
32         if($zt)
33         {
34             $str = "<span style=' color:green'>已通过</span><a href='bohui.php?uid={$v[0]}'>驳回</a>";
35         }
36         else
37         {
38             $str = "<a href='tongguo.php?uid={$v[0]}'>通过</a>";
39         }
40         
41         echo "<tr>
42         <td>{$v[0]}</td>
43         <td>{$v[1]}</td>
44         <td>{$v[2]}</td>
45         <td>{$v[3]}</td>
46         <td>{$v[4]}</td>
47         <td>{$str}</td>
48     </tr>";
49     }
50     
51     ?>
52 
53 
54 </table>
55 
56 </body>
57 </html>
shenhechuli.php

6.审核处理(驳回处理(和审核通过一样))

 1 <?php
 2 
 3 $uid = $_GET["uid"];
 4 
 5 include("../fengzhuang/DBDA.class.php");
 6 $db = new DBDA();
 7 
 8 $sql = "update users set isok=0 where uid='{$uid}'";
 9 $db->Query($sql,0);
10 
11 header("location:shenhe.php");
bohui.php

 

贰.批量删除:

1.主界面

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9 <form action="shanchu.php" method="post">
10 <table width="100%" border="1" cellpadding="0" cellspacing="0">
11     <tr>
12         <td><input type="checkbox" id="qx" οnclick="xuanzhong()" />全选</td>
13         <td>代号</td>
14         <td>名称</td>
15     </tr>
16     
17     <?php
18     include("../fengzhuang/DBDA.class.php");
19     $db = new DBDA();
20     
21     $sql = "select * from nation";
22     $attr = $db->Query($sql);
23     
24     foreach($attr as $v)
25     {
26         echo "<tr>
27         <td><input type='checkbox' name='ck[]' class='ck' value='{$v[0]}' /></td>
28         <td>{$v[0]}</td>
29         <td>{$v[1]}</td>
30     </tr>";
31     }
32     
33     ?>
34     
35 </table>
36 <input type="submit" value="删除" οnclick="return tishi()" />
37 </form>
38 </body>
39 <script type="text/javascript">
40     function xuanzhong()
41     {
42         //取全选按钮的选中状态
43         var zt = document.getElementById("qx").checked;
44         
45         //让下面所有的checkbox选中状态改变
46         var ck = document.getElementsByClassName("ck");
47         
48         for(var i=0;i<ck.length;i++)
49         {
50             if(zt)
51             {
52                 ck[i].setAttribute("checked","checked");
53             }
54             else
55             {
56                 ck[i].removeAttribute("checked");
57             }
58         }
59     }
60     
61     function tishi()
62     {
63         //找所有选中项
64         var ck = document.getElementsByClassName("ck");
65         
66         var str = "";
67         
68         for(var i=0;i<ck.length;i++)
69         {
70             if(ck[i].checked)
71             {
72                 str += ck[i].value+",";
73             }
74         }
75         
76         return confirm("确定要删除以下数据么:"+str+"");
77     }
78 </script>
79 </html>
main.php

2.处理界面

 1 <?php
 2 $ck = $_POST["ck"];
 3 
 4 include("../fengzhuang/DBDA.class.php");
 5 $db = new DBDA();
 6 
 7 //第一种方式
 8 /*foreach($ck as $v)
 9 {
10     $sql = "delete from nation where code='{$v}'";
11     $db->Query($sql,0);
12 }*/
13 
14 //第二种方式
15 //in ('','','','','')
16 $str = implode("','",$ck);
17 
18 $str = "('{$str}')"; 
19 
20 $sql = "delete from nation where code in {$str}";
21 $db->Query($sql,0);
22 
23 header("location:main.php");
shanchu.php

 

转载于:https://www.cnblogs.com/ordinaryk/p/6233703.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值