小编nic*_*cng的帖子

php运行一次并在mysql数据库中插入两次

我在下面有一个简单的代码.运行一次后,它会将结果两次插入mysql数据库.

如果它在页面上1次刷新时运行两次或请求两次,为什么输出只有1个结果?

我一直在谷歌上搜索,并努力解决这个问题.但是,我没有弄清楚这段代码有什么问题.代码在localhost上运行完美,但在将其移动到服务器后,问题会弹出.以前有人遇到过这样的事吗?如何解决这个问题?

完整代码:

<?php
$db=mysql_connect('localhost','zzzzzzz','xxxxxx') or die('Unable to connect.'.mysql_error());
mysql_select_db('test',$db) or die(mysql_error($db));

$sql="INSERT INTO test_table(value,insert_time) VALUES ('testing','".time()."')";
$result=mysql_query($sql);
echo "result=".$result;

$select="select * from test_table";
$rs=mysql_query($select);
while($row=mysql_fetch_array($rs)){
echo $row["test_id"]." -- ".$row["value"]." -- ".$row["insert_time"]."<br />";
}
?>
Run Code Online (Sandbox Code Playgroud)

结果:
结果= 1
1 - 测试 - 1298185509

但是在数据库中:
test_id,value,insert_time
1,testing,1298185509
2,testing,1298185511

php mysql insert

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

insert ×1

mysql ×1

php ×1