因为你每次刷新都会执行这一段:
<?php
$link_id=mysql_connect("172.18.13.227","root","");
mysql_select_db("bc_booK");
$str="insert into porducts(pname,price,author) values ('$pname','$price','$author')";
$result=mysql_query( $str,$link_id);
mysql_close($link_id);
?>
<?php
$link_id=mysql_connect("172.18.13.227","root","");
mysql_select_db("bc_booK");
$str="insert into porducts(pname,price,author) values ('$pname','$price','$author')";
$result=mysql_query( $str,$link_id);
mysql_close($link_id);
?>
我是随便写的,你要调试一下。<?php
if ($type == 'add'){
$link_id=mysql_connect("172.18.13.227","root","");
mysql_select_db("bc_booK");
$str="insert into porducts(pname,price,author) values ('$pname','$price','$author')";
$result=mysql_query( $str,$link_id);
mysql_close($link_id);
header('location:fume.php');
}
?><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="eaeaea">
<div align="center"><strong>〖商品填加〗</strong></div>
<hr noshade><br>
<form action="fume.php" method="post">
<br>
产品名称:
<input type="text" size="15" name="pname">
<br>
产品价格:
<input type="text" size="15" name="price">
<br>
产品作者:
<input type="text" size="5" name="author">
<input type="hidden" name="type" value="add">
<br>
<br>
<input type="submit" value="确定">
<input type="reset" value="清除">
</form>
<?php
}
//显示页面
$link_id=mysql_connect("172.18.13.227","root","");
mysql_select_db("bc_book");
$str="select * from porducts order by psn desc;";
$result=mysql_query($str,$link_id);
mysql_close($link_id);
$l=mysql_num_rows($result);
for ($i=1;$i<=$l;$i++)
{
list (,$pname,$price,$author)=mysql_fetch_row($result);
?>
<table width="75%" border="1" cellpadding="2" cellspacing="0" bordercolor="#000000">
<tr>
<td>产品序号</td>
<td><div align="center">产品名称</div></td>
<td><div align="center">产品价格</div></td>
</tr>
<? for ($i=1;$i<=$l;$i++)
{ ?>
<tr>
<td><? echo $psn ?></td>
<td><? echo $pname ?></td>
<td><? echo $price ?></td>
</tr>
</table>
<? };?>
</body>
</html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="eaeaea">
<div align="center"><strong>〖商品填加〗</strong></div>
<hr noshade><br>
<form action="fume.php" method="post">
<br>
产品名称:
<input type="text" size="15" name="pname">
<br>
产品价格:
<input type="text" size="15" name="price">
<br>
产品作者:
<input type="text" size="5" name="author">
<br>
<br>
<input type="submit" value="确定">
<input type="reset" value="清除">
</form>
</body>
</html>-----------------------------------
fume.php:<?php
$link_id=mysql_connect("172.18.13.227","root","");
mysql_select_db("bc_booK");
$str="insert into porducts(pname,price,author) values ('$pname','$price','$author')";
$result=mysql_query( $str,$link_id);
mysql_close($link_id);header("Location:myshow.php");
exit(); ?>-----------------------------------------myshow.php:<?php
//显示页面
$link_id=mysql_connect("172.18.13.227","root","");
mysql_select_db("bc_book");
$str="select * from porducts order by psn desc;";
$result=mysql_query($str,$link_id);
mysql_close($link_id);
$l=mysql_num_rows($result);
for ($i=1;$i<=$l;$i++)
{
list (,$pname,$price,$author)=mysql_fetch_row($result);
?>
<table width="75%" border="1" cellpadding="2" cellspacing="0" bordercolor="#000000">
<tr>
<td>产品序号</td>
<td><div align="center">产品名称</div></td>
<td><div align="center">产品价格</div></td>
</tr>
<? for ($i=1;$i<=$l;$i++)
{ ?>
<tr>
<td><? echo $psn ?></td>
<td><? echo $pname ?></td>
<td><? echo $price ?></td>
</tr>
</table>
<? };?>
</body>
</html>