zoukankan      html  css  js  c++  java
  • php 增删改查范例(2)

    增加页面add.php:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <form method="post" action="addpost.php">
            <input type="text" name="name" placeholder="姓名">
            <input type="radio" name="sex" value="1" id="man"><label for="man">男</label>
            <input type="radio" name="sex" value="0" id="woman"><label for="woman">女</label>
            <input type="text" name="age" placeholder="年龄">
            <input type="text" name="birthday" placeholder="出生年月">
            <input type="submit" value="提交">
        </form>
    </body>
    </html>

    增加处理页面addpost.php:

    <?php
    $name = $_POST['name'];
    $sex = $_POST['sex'];
    $age = $_POST['age'];
    $birthday = $_POST['birthday'];

    $db = new Mysqli("localhost","root","root","db_0808");
    $sql = "INSERT INTO `user` VALUES (null,'{$name}',{$sex},'{$birthday}',{$age},DEFAULT,0)";
    //var_dump($db->query($sql));
    if($db->query($sql)){
        header("location:index.php");
    }else{
        header("location:add.php");
    }
    删除页面delete.php:

    <?php
    $id=$_GET['id'];
    $db= new mysqli('localhost','root','root','db_0808');
    mysqli_connect_error()?die("链接出错"):"";
    //$sql="delect from user where id={$id}";
    $sql2="update user set is_delete = '1' where id={$id} ";
    //var_dump ($db->query($sql2));
    if($db->quary(sql2)){
        header("location:index.php");
    }
    批量删除页面batch_delete.php:

    <?php
    var_dump  ($_POST['ids']);

    $db = new Mysqli('localhost','root','root','db_0808');
    mysqli_connect_error()?die("链接出错"):"";
    //$sql =  "delete from USER WHERE id = {$id}";
    //方法1
    foreach($ids as $i){
    $sql2 = "update user set is_delete = '1' WHERE  id = {$i}";
    $result=$db->query($sql2);
    }
    //方法2
    //$sql_str=implode(",",$ids);
    //$sql2 = "update user set is_delete = '1' WHERE  id in ({$sql_str})";
    //$result=$db->query($sql2);
    echo "success!";
    ?>

  • 相关阅读:
    css文本在标签<text>内平均分布
    ES6实现去重,排序,加升序
    uni-app项目打包成小程序
    uni-app项目( uniapp滚动监听元素)
    运行vue项目:Module build failed: Error: Cannot find module 'node-sass'报错问题
    笨方法实现数量的输入与加一减一 、以及对边界值的判断禁用
    基于nuxt的前端商城pc端项目(bug记录)
    基于nuxt的商城项目pc端项目记录
    Vue学习笔记整理-长期更新
    程序员,不要创业!
  • 原文地址:https://www.cnblogs.com/cmzhphp2017/p/7838451.html
Copyright © 2011-2022 走看看