1做一个添加数据的页面
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 <style type="text/css"> 7 #a{ 400px; height:300px;} 8 </style> 9 </head> 10 11 <body> 12 <h1>房屋租赁信息:</h1> 13 <form action="./tjhouse.php" method="post"> 14 <div id="a" align="right"> 15 <div>关键字:<input type="text" name="keyword" /></div> 16 <div>区域:<input type="text" name="area" /></div> 17 <div>使用面积:<input type="text" name="squaremeter" /></div> 18 <div>租金:<input type="text" name="rent" /></div> 19 <div>租赁类型:<input type="text" name="renttype" /></div> 20 <div>房屋类型:<input type="text" name="housetype" /></div></div> 21 <input type="submit" value="更新"> 22 <a href="tianjiahouse.php"><input type="button" value="取消"></a> 23 </form> 24 </body> 25 </html>
做一个处理页面,将input里的keyword,area,squaremeter,rent,renttype,housetype通过form表单$_POST方式传值到tianjiahouse.php,要一一对应。
在写SQL语句添加时注意要将ids的值写个0放进去,不要漏了;
当SQL为增删改语句时在判断result时用$db->query($sql,1),
当SQL为查询语句时$db->query($sql),得到的是数组
1 <?php 2 $keyword = $_POST["keyword"]; 3 $area = $_POST["area"]; 4 $squaremeter = $_POST["squaremeter"]; 5 $rent = $_POST["rent"]; 6 $renttype = $_POST["renttype"]; 7 $housetype = $_POST["housetype"]; 8 require_once "./DBDA.class.php"; 9 $db = new DBDA();//这是加载DBDA的格式 10 $sql = "insert into house values(0,'{$keyword}','{$area}','{$squaremeter}','{$rent}','{$renttype}','{$housetype}')"; 11 $result = $db->query($sql,1); 12 if($result){ 13 echo "<script type='text/javascript'>window.location.href='housejs.php';</script>"; 14 }else{ 15 echo "添加失败!"; 16 }
在网页上显示结果如下