• php 增删改查范例(3)


    编辑页面edit.php:

    <?php
    $id=$_GET['id'];
    $db= new mysqli('localhost','root','root','db_0808');
    $sql="select * from `user` where id={$id} ";
    $result=$db->query($sql);
    $data=$result->fetch_assoc();
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <form action="editpost.pop" method="get">
        <input type="hidden" name="id" value="<?php echo $data['id']?>">
        <input type="text" name="name" placeholder="姓名" value="<?php echo $data['name']?>">
        <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="birthday"  value="<?php echo $data['birthday']?>" placeholder="出生年月">
        <input type="submit" value="提交">
    </form>
    </body>
    </html>
    编辑处理页面editpost.pop:

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

  • 相关阅读:
    CF1328B K-th Beautiful String
    CF1327B Princesses and Princes
    CF750D New Year and Fireworks
    CF57C Array
    洛谷P5661 公交换乘(CSP-J 2019 T2)
    Docker原理:Cgroup
    Docker原理:Namespace
    Anaconda软件安装使用问题
    初步了解Unix系统的I/O模式
    深入理解索引和AVL树、B-树、B+树的关系
  • 原文地址:https://www.cnblogs.com/cmzhphp2017/p/7838459.html
Copyright © 2020-2023  润新知