zoukankan      html  css  js  c++  java
  • 修改数据

    03.php

    <?php
    $conn=mysql_connect("localhost","root","111111");
    mysql_query("set names utf8",$conn);//设置编码
    mysql_query("use test1",$conn);//选库
    $id=addslashes($_GET['id']);
    $sql="select id,name,gender from stu where id=".$id;
    $rs=mysql_query($sql,$conn);
    $arr=mysql_fetch_array($rs);
    ?>
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>编辑</title>
    </head>
    <body>
    <form action=<?php echo "04.php?id=".$id;?> method="post">
    <table border=1 width="50%">
        <tr>
            <td>id</td>
            <td><?php echo $arr["id"]; ?></td>
        </tr>
        <tr>
            <td>name</td>
            <td><input type="text" name="name" value="<?php echo $arr['name']?>"></td>
        </tr>
        <tr>
            <td>gender</td>
            <td><input type="text" name="gender" value="<?php echo $arr['gender']?>"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="保存修改"></td>
        </tr>
    </table>
     </form>   
    </body>
    </html>
    

     04.php

    <?php
    $conn=mysql_connect("localhost","root","111111");
    mysql_query("set names utf8",$conn);//设置编码
    mysql_query("use test1",$conn);//选库
    $id=$_GET['id']+0;
    $name=addslashes($_POST['name']);
    $gender=addslashes($_POST['gender']);
    $sql="update stu set name='".$name."',gender='".$gender."' where id=".$id;
    $rs=mysql_query($sql,$conn);
    if(mysql_affected_rows($conn)==0){
        echo "修改失败,可能与原数据一样";
    }else{
        echo "修改成功";
    }
    echo "<a href='01.php'>返回</a>";
    
    ?>
    
  • 相关阅读:
    第一周、学习嵌入式
    centos7及xfce桌面环境安装,远程工具配置使用方法
    第一次作业
    2018下C语言基础课第1次作业
    第二次作业
    第一次作业
    第0次作业
    博客园第五次作业
    博客园第四次作业
    博客园第三次作业
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4735173.html
Copyright © 2011-2022 走看看