• 增删


    
    
            <h1>列表</h1>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>代号</td>
            <td>名称</td>
            <td>价格</td>
            <td>产地</td>
            <td>库存</td>
            <td>操作</td>
        </tr>
    
    
    
    
    <?php
    $db = new MySQLi("localhost","root","112834","test4");
    
    $sql = "select * from hao";
    
    $result = $db->query($sql);
    
    /*$attr = $result->fetch_all();
    
    foreach($attr as $v)
    {
        echo "<tr><td>($v[0])</td><td>($v[1])</td><td>($v[2])</td><td>($v[3])</td><td>($v[4])</td></tr>";    
    }
    */
    while($attr = $result->fetch_row())
    {
        echo "<tr><td>($attr[0])</td><td>($attr[1])</td><td>($attr[2])</td><td>($attr[3])</td><td>($attr[4])</td><td><a href='shanchu.php?name={$attr[1]}' onclick="return confirm('确定删除么')">删除</a></td></tr>";    
    }
    
    
    ?>
    </table>
    $name =$_GET["name"];
    
    
    $db = new MySQLi("localhost","root","112834","test4");
    
    
    $sql = "delete from hao where name='{$name}'";
    $r = $db->query($sql);
    if($r)
    {
        header("location:biaoge.php");    
    }
    else
    {
        echo "删除失败";    
    }


    <h1>添加</h1>
    <form action="tianjia.php" method="post">
    <div>名称 <input type="text" name="name" /></div>
    <div>价格 <input type="text" name="price" /></div>
    <div>产地 <input type="text" name="chandi" /></div>
    <div>库存 <input type="text" name="numbers" /></div>
    <div><input type="submit" value="添加" /></div>
    
    
    </form>
    
    
    <?php
    $name = $_POST["name"];
    $price = $_POST["price"];
    $chandi = $_POST["chandi"];
    $numbers = $_POST["numbers"];
    
    
    $db = new MySQLi("localhost","root","112834","test4");
    
    
    $sql = "insert into hao values ('','{$name}','{$price}','{$chandi}',{$numbers})";
    $r = $db->query($sql);
    if($r)
    {
        header("location:biaoge.php");    
    }
    else
    {
        echo "添加失败";    
    }
    ?>

     
    
    
    
    
    
  • 相关阅读:
    斐波纳契数列
    实现刮刮乐的效果
    简易版美图秀秀
    js 宏任务和微任务
    作业3 阅读
    作业2 结对子作业
    做汉堡
    练习一
    Java设计模式十八:代理模式(Proxy)
    Java设计模式二十:适配器模式(Adapter)
  • 原文地址:https://www.cnblogs.com/hao0/p/6196943.html
Copyright © 2020-2023  润新知