php修改数据

修改数据页面代码

设置的name值是用来提交给处理页面的

后面的value值是当你点击需要修改的那条内容时把此条内容的所有信息显示出来

10-16行是将获得上面的主键值获得所有数据

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9 <?php
10 //取出主键值
11 $ids = $_GET["ids"];
12 //读取该条数据
13 $db = new MySQLi("localhost","root","123","phptext");
14 $sql = "select * from house where ids={$ids}";
15 $result = $db->query($sql);
16 $arr1 = $result->fetch_row();
17 ?>
18 <form action="./xgneirong.php" method="post">
19 <div id="a" align="right">
20 <input type="hidden" name="ids" value="<?php echo $arr1[0] ?>">
21 <div>关键字:<input type="text" name="keyword" value="<?php echo $arr1[1] ?>" /></div>
22 <div>区域:<input type="text" name="area" value="<?php echo $arr1[2] ?>" /></div>
23 <div>使用面积:<input type="text" name="squaremeter" value="<?php echo $arr1[3] ?>"/></div>
24 <div>租金:<input type="text" name="rent" value="<?php echo $arr1[4] ?>" /></div>
25 <div>租赁类型:<input type="text" name="renttype" value="<?php echo $arr1[5] ?>" /></div>
26 <div>房屋类型:<input type="text" name="housetype" value="<?php echo $arr1[6] ?>"/></div></div>
27 <input type="submit" value="修改">
28 <a href="tianjiahouse.php"><input type="button" value="取消"></a>
29 </form>
30 </body>
31 </html>

用form表单提交给php页面处理,需要将ids的值也一并传过来,有时会出现ids找不到的错误

<meta charset="utf-8">
<?php
$ids = $_POST["ids"];
$keyword = $_POST["keyword"];
$area = $_POST["area"];    
$squaremeter = $_POST["squaremeter"];
$rent = $_POST["rent"];
$renttype = $_POST["renttype"];
$housetype = $_POST["housetype"];
require_once "./DBDA.class.php";
$db = new DBDA();
$sql = "update house set
keyword='{$keyword}',area='{$area}',squaremeter='{$squaremeter}',rent='{$rent}',renttype='{$renttype}',housetype='{$housetype}' where ids={$ids}";
$result = $db->query($sql,1);
if($result){
        echo "<script type='text/javascript'>window.location.href='housejs.php';</script>";
    }else{
        echo "修改失败!";
        }

 

posted @ 2018-01-21 15:41  FTHeD  阅读(211)  评论(0编辑  收藏  举报