zoukankan      html  css  js  c++  java
  • php 数据库的增删改查

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <?php
    $db= new Mysqli("localhost","root","root","asd_8080");
    //empty(mysqli_connect_error())?"":die("连接错误");


    $sql="select * from user where is_delete='0'";
    $data= $db->query($sql)->fetch_all();
    if (!empty($_POST)){
    $name = $_POST['name'];
    $sex = $_POST['sex'];
    $birth_start=$_POST['birth_start'];
    $birth_end = $_POST['birth_end'];

    $sql .= !empty($name)? "and name like '%{$name}%'":"";
    $sql .= !empty($sex)? "and sex like '%{$sex}%'":"";
    }



    ?>
    <form action="mxdx2.php" method="post">
    <table>
    <tr>
    <td>姓名:<input type="text" name="name"></td>
    <td>性别:
    <select name="sex">
    <option value="1">男</option>
    <option value="0">女</option>
    </select>
    </td>
    <td>
    年龄:<input type="text" name="birth_start">---<input type="text" name="birth_end">
    </td>
    <td>
    <input type="submit" value="查询">
    </td>
    </tr>
    </table>
    </form>
    <form action="plsc.php" method="post">
    <table border="1">
    <form border="2">
    <tr>
    <td>ID</td>
    <td>姓名</td>!
    <td>性别</td>
    <td>年龄</td>
    <td>出生年月</td>
    </tr>
    <?php
    foreach ($data as $i){
    if ($i[2]== 1 ){
    $i[2]="男";
    }else if ($i[2]== 0 ){
    $i[2]="女";
    }else{
    $i[2]="保密";
    }
    echo "<tr><td>{$i[0]}<input type='checkbox' name='ids[]' value='{$i[0]}'></td><td>{$i[1]}</td><td>{$i[2]}</td><td>{$i[3]}</td><td>{$i[4]}</td><td><a href='mxdx3.php?id={$i[0]}'>删除</a></td>&nbsp;&nbsp;<td><a href='edit.php?id={$i[0]}'>修改</a></td></tr>";
    }
    ?>


    </table>
    <input type="submit" value="批量删除">
    </form>
    <a href="add.php">新增用户</a>

    </body>
    </html>



    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <form method="post" action="addpost.php">
    <input type="text" name="name">
    <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="create_time" placeholder="出生年月">
    <input type="submit" value="提交">
    </form>

    </body>
    </html>

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


    $db = new Mysqli("localhost","root","root","asd_8080");
    $sql = "INSERT INTO user VALUES (NULL ,'{$name}',{$sex},'{$age}',{$birthday},'0')";
    if($db->query($sql)){
    header("location:mxdx2.php");
    }else{
    header("location:add.php");
    }



    <?php
    $id = $_GET['id'];

    $db= new Mysqli("localhost","root","root","asd_8080");
    mysqli_connect_error()?die("连接出错"):"";
    $sql = "delete from USER WHERE id = {$id}";
    $sql2 = "update user set is_delete ='1' WHERE id ={$id}";
    if ($db->query($sql2)){
    header("location:mxdx2.php");

    }



    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <form action="editpost.php" method="post">
    <input type="hidden" name="id" value="<?php echo $data['id']?>">
    <input type="text" name="neme" value="<?php echo $data['neme']?>">
    <input type="radio" name="sex" value="1" <?php if ($data['sex']==1){echo 'checked';}?> id="man" ><label for="man">男</label>
    <input type="radio" name="sex" value="0" <?php if ($data['sex']==0){echo 'checked';}?> id="woman" ><label for="woman">女</label>
    <input type="text" name="age" value="<?php echo $data['age']?>" placeholder="年龄">
    <input type="text" name="create_time" placeholder="出生年月" value="<?php echo $data['create_time']?>">
    <input type="submit" value="提交">
    </form>

    </body>
    </html>


    <?php
    $id=$_POST['id'];
    $name = $_POST['neme'];
    $sex = $_POST['sex'];
    $age=$_POST['age'];
    $birthday = $_POST['create_time'];
    var_dump($name);
    $db= new Mysqli("localhost","root","root","asd_8080");
    $sql = "update `user` set neme='{$name}',sex='{$sex}',age ={$age},create_time='{$birthday}'WHERE id={$id}";
    if ($db->query($sql)){
    echo "执行成功";
    }






  • 相关阅读:
    tcpdump抓localhost 127.0.0.1的包
    fatal: write failure on 'stdout': Bad file descriptor
    rst转html
    Call to WHvSetupPartition failed: ERROR_SUCCESS (Last=0xc000000d/87) (VERR_NEM_VM_CREATE_FAILED)
    error: 'readdir_r' is deprecated [-Werror=deprecated-declarations]
    ubuntu虚拟机设置共享后无权限
    VirtualBox怎么设置从u盘启动,虚拟机从U盘启动
    File类总结
    相对路径的写法
    systeminfo总结
  • 原文地址:https://www.cnblogs.com/ping04/p/7700330.html
Copyright © 2011-2022 走看看