mate1988 阅读(1905) 评论(0)
用户界面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "外链网址已屏蔽www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="外链网址已屏蔽www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <form action="add.php" method="post"> <table border="1" width="600"> <tr> <td>商品名称</td> <td> <input type="text" name="gname" /> </td> </tr> <tr> <td>商品价格</td> <td> <input type="text" name="jiage" /> </td> </tr> <tr> <td> <input type="submit" value="OK" /> </td> </tr> </table> </form> </body> </html>
储存用户界面填写的内容
<?php
return array ();
?>
PHP后台数据处理的的代码页面

<?php
function p($arr){
echo"<pre>";
print_r ($arr);
echo"<pre>";

}
$data=include"./goodsdb.php";
$data[]= $_POST;
header("Content-type:text/html;charset=utf-8");
if(file_put_contents("goodsdb.php","<?php\nreturn ".var_export($data,true).";\n?>")){
	
	echo '<script>alert("商品添加成功");location.href="list.php";</script>';
}

?>
数据处理后列表页
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "外链网址已屏蔽www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="外链网址已屏蔽www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
$goods =include("goodsdb.php");
?>
<?php
foreach ($goods as $id=>$g) {
?>
<li>
<a href="goods.php?id=<?php echo $id?>"><?php echo "[".($id+1)."]".$g["gname"];?></a>

</li> 
<?php }?>

</body>
goods.php页面
<?php
$data = include("goodsdb.php");
include("tpl/goods.html");
?>
视图页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "外链网址已屏蔽www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="外链网址已屏蔽www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>无标题文档</title>
</head>

<body>
<?php
$id=$_GET["id"];
$db=include("goodsdb.php");
?>
<table border="1" width="600">
<tr>
<td>商品名称</td>
<td>
<?php echo $db[$id]["gname"];?>
</td>
</tr>
<tr>
<td>商品价格</td>
<td><?php echo $db[$id]["jiage"]; ?></td>
</tr>

</table>

</body>
</html>
</html>

发表评论
切换编辑模式