码迷,mamicode.com
首页 > 其他好文 > 详细

修改数据

时间:2015-08-16 23:00:02      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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>";

?>

 

修改数据

标签:

原文地址:http://www.cnblogs.com/lzzhuany/p/4735173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!