因为你每次刷新都会执行这一段:
<?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);
?>
解决方案 »
- 请教javascript如何获取PHP字符串类型数组的值?
- 高手帮忙修改一下类
- CGI程序的运行权限
- 全部变量的问题?
- 利用php作简单的搜索引擎:怎么在被搜索网站的log中出现这样的字符 Baiduspider+(+http://www.baidu.com/search/spider.htm)
- 请问在PHP中如何读写以及创建.ini文件?
- 修改文件夹的权限,怎么就不能执行了?
- 删除重复数据加强版(原厂)
- 寻找用PHP做ZIP压缩文件的程序
- #Win2000Server + apache2.0.49 +php-4.3.5-Win32.zip ?
- ORACLE数据库与PHP的问题!参与者也有分,写完程序给100分
- 求职:我是广州大学生,急求PHP工作增加经验,薪水多低也愿意
我是随便写的,你要调试一下。<?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>