zoukankan      html  css  js  c++  java
  • 6.12 php对数据库的查询,新增和修改

    //主页查询

    <?php
    $bt = empty($_POST['bt'])?'':$_POST['bt'];
    $zz = empty($_POST['zz'])?'':$_POST['zz'];
    ?>
    <!DOCTYPE html>
    <html lang="zh">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <!--引入bootstrap css文件-->
    <link rel="stylesheet" href="css/js/css/bootstrap.min.css"/>
    <!--引入jQuery-->
    <script src="css/js/jquery-3.3.1.min.js"></script>
    <script src="css/js/bootstrap.min.js"></script>
    <title>Document</title>
    </head>
    <body>
    <form action="" method="post">
    标题 :<input type="text" name="bt" id="" value="<?php echo $bt;?>" /><!--输上值可以保留-->
    作者 :<input type="text" name="zz" id="" value="<?php echo $zz;?>" />
    <input type="submit" name="" id="" value="查询"/>
    </form>
    <form action="piliang.php" method="post">
    <table border="1px" cellspacing="" cellpadding=""class="table table-dark">
    <tr>
    <td><input type="checkbox" onclick="quanxuan(this)"/></td>
    <td>序号</td>
    <td>标题</td>
    <td>作者</td>
    <td>来源</td>
    <td>内容</td>
    <td>发布时间</td>
    <td>修改</td>
    <td>删除</td>
    </tr>
    <?php
    $severname = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "ceshi";
    $conn = new mysqli($severname,$dbuser,$dbpassword,$dbname);
    if($conn->connect_error){
    die("链接失败");
    }
    $sql = "select * from wz where biaoti like '%$bt%' and zuozhe like '%$zz%'";
    //一进页面两个条件为空,所以还是查询所有
    $result = $conn->query($sql);
    $attr = $result->fetch_all();
    $str = "";
    for($i=0;$i<count($attr);$i++){
    $str.="<tr>";
    $str.="<td><input type='checkbox' name='ck[]' id='' value='{$attr[$i][0]}' class='qx'/></td>";
    //name='ck[]' 如果不加[]后面传值没法传数组,后面名字不用[];
    for($j=0;$j<count($attr[$i]);$j++){
    $str.="<td>{$attr[$i][$j]}</td>";
    }
    $str.="<td><a href='xiugai.php?bs={$attr[$i][0]}'>修改</a></td>";
    $str.="<td><a href='shanchu.php?bs={$attr[$i][0]}'>删除</a></td>";
    $str.="</tr>";
    }
    echo $str;
    ?>
    </table>
    <input type="submit" value="批量删除"/>
    </form>
    <a href="xinzeng.php">新增</a>
    </body>
    </html>
    <script type="text/javascript">
    function quanxuan(t) {
    var aa = document.getElementsByClassName("qx");
    for (var i=0;i<aa.length;i++) {
    if (t.checked==true) {
    aa[i].checked=true;
    }else if(t.checked==false){
    aa[i].checked=false;
    }
    //aa[i].checked = t.checked?true:false;
    }

    }
    </script>

    //新增

    <!DOCTYPE html>
    <html lang="zh">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    </head>
    <body>
    <form action="xinzengchuli.php" method="post">
    序号:<input type="text"name="xh" value="" /><br>
    标题:<input type="text"name="bt" value="" /><br>
    作者:<input type="text"name="zz" value="" /><br>
    来源:<input type="text"name="ly" value="" /><br>
    内容:<input type="text"name="nr" value="" /><br>
    时间:<input type="text"name="sj" value="" /><br>
    <input type="submit" name="" id="" value="确定" />
    </form>
    </body>
    </html>

    //新增处理

    <?php
    $severname = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "ceshi";
    $conn = new mysqli($severname,$dbuser,$dbpassword,$dbname);
    $xh = $_POST['xh'];
    $bt = $_POST['bt'];
    $zz = $_POST['zz'];
    $ly = $_POST['ly'];
    $nr = $_POST['nr'];
    $sj = $_POST['sj'];
    $sql = "insert into wz values('$xh','$bt','$zz','$ly','$nr','$sj')";
    $result = $conn->query($sql);
    ?>

    //修改

    <?php
    $bs=$_GET['bs'];
    $severname = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "ceshi";
    $conn = new mysqli($severname,$dbuser,$dbpassword,$dbname);
    $sql = "select * from wz where id = '$bs'";
    $result = $conn->query($sql);
    $attr = $result->fetch_row();
    ?>
    <!DOCTYPE html>
    <html lang="zh">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    </head>
    <body>
    <form action="xiugaicl.php" method="post">
    序号:<input type="text"name="xh" value="<?php echo $attr[0];?>" /><br>
    标题:<input type="text"name="bt" value="<?php echo $attr[1];?>" /><br>
    作者:<input type="text"name="zz" value="<?php echo $attr[2];?>" /><br>
    来源:<input type="text"name="ly" value="<?php echo $attr[3];?>" /><br>
    内容:<input type="text"name="nr" value="<?php echo $attr[4];?>" /><br>
    时间:<input type="text"name="sj" value="<?php echo $attr[5];?>" /><br>
    <input type="submit" name="" id="" value="确定" />
    </form>
    </body>
    </html>

    //修改处理

    <?php
    $severname = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "ceshi";
    $conn = new mysqli($severname,$dbuser,$dbpassword,$dbname);

    $xh = $_POST['xh'];
    $bt = $_POST['bt'];
    $zz = $_POST['zz'];
    $ly = $_POST['ly'];
    $nr = $_POST['nr'];
    $sj = $_POST['sj'];
    $sql = "update wz set id='$xh',biaoti='$bt',zuozhe='$zz',laiyuan='$ly',neirong='$nr',shijian='$sj' where id ='$xh'";
    $result = $conn->query($sql);
    var_dump($result);
    header("Location:0612.php");
    ?>

  • 相关阅读:
    打sql server pack4后打开网站报错的解决办法
    北京大学的三角形文章
    一次SQL Server 2000修复实践的说明
    今天重看了几集《将爱情进行到底》
    MakeFile的写法
    [经验杂谈]与大虾对话:领悟设计模式zz
    论函数调用约定(zz)
    用标准模板库STL实现文件比较(zz)
    C++中的虚函数(virtual function)
    为学院科研办做的个小应用管理程序
  • 原文地址:https://www.cnblogs.com/sunhao1987/p/9174975.html
Copyright © 2011-2022 走看看