为什么通过php在向mysql插入数据时会同时插入两条相同的数据
1个回答
展开全部
这是url传递参数的代码:
XML/HTML code?
<td align="left"><a href="choose.php?relation_id='.$row['user_id'].'&user_id='.$_COOKIE['user_id'].'">一键关注</a></td>
;
这是插入数据库的代码:
PHP code?
<?php
header("Content-Type:text/html; charset=utf-8");
include('MY_PHP_file/mysql_connect.php');
$user_id = $_GET['user_id'];
$relation_id = $_GET['relation_id'];
$sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES ('$user_id', '$relation_id', now())";
$state = mysql_query($sql);
if($state)
{
echo "<script>alert('一键关注成功!!'); location.href='user_action.php';</script>";
}
else
echo '<script>alert("一键关注失败,请重试!!"); location.href="user_action.php";</script>';
?>
$state = mysql_query($sql);
if($state)
按我的理解这里执行了两次。
解决方法直接是 if(mysql_query($sql))就可以了
XML/HTML code?
<td align="left"><a href="choose.php?relation_id='.$row['user_id'].'&user_id='.$_COOKIE['user_id'].'">一键关注</a></td>
;
这是插入数据库的代码:
PHP code?
<?php
header("Content-Type:text/html; charset=utf-8");
include('MY_PHP_file/mysql_connect.php');
$user_id = $_GET['user_id'];
$relation_id = $_GET['relation_id'];
$sql = "INSERT INTO user_action (user_id, relation_id, concern_time) VALUES ('$user_id', '$relation_id', now())";
$state = mysql_query($sql);
if($state)
{
echo "<script>alert('一键关注成功!!'); location.href='user_action.php';</script>";
}
else
echo '<script>alert("一键关注失败,请重试!!"); location.href="user_action.php";</script>';
?>
$state = mysql_query($sql);
if($state)
按我的理解这里执行了两次。
解决方法直接是 if(mysql_query($sql))就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询