我正在努力建立一个跟随系统 - 有点像Twitter有的。出于某种原因,当我单击“跟随”按钮时,没有任何内容添加到数据库中。我该如何解决这个问题?
我的代码是:
$my_id = $_SESSION['user_id'];
$u_id1 = $_GET['id'];
$check = mysqli_query($con,"SELECT id FROM follow WHERE user_one='$my_id' AND user_two='$u_id1'");
if(mysqli_num_rows($check) == 1) {
echo "<a href='follow_action.php?do=unfollow&user_id=$u_id1'>Unfollow</a> ";
}
else {
echo "<strong><a href='follow_action.php?do=follow&user_id=$u_id1'>Follow</a></strong>";
}
在follow_action.php文档中,我有这段代码:
$my_id = $_SESSION['user_id'];
$user_id = $_GET['user_id'];
$followAction = "INSERT INTO follow VALUES ('', '$my_id', '$user_id')";
$unfollowAction = "DELETE FROM 'follow' WHERE 'user_one'='$my_id' AND 'user_two'='$user_id'";
$u_id1 = $_GET['user_id'];
if( $do == ['follow'] ) {
mysqli_query( $con, $followAction );
}
if( $do == ['unfollow'] ) {
mysqli_query( $con, $unfollowAction );
}
$user_id3 = $_GET['user_id'];
header('Location:users.php?id='.$user_id3);
数据库中的下表包含以下行:id,user_one和user_two - user_one是登录用户,user_two是想要被关注的用户。
答案 0 :(得分:0)
您在follow_action.php文件中更改 像这样
$my_id = $_SESSION['user_id'];
$user_id = $_GET['user_id'];
$do = $_GET['do'];
$followAction = "INSERT INTO follow VALUES ('', '$my_id', '$user_id')";
$unfollowAction = "DELETE FROM 'follow' WHERE 'user_one'='$my_id' AND 'user_two'='$user_id'";
$u_id1 = $_GET['user_id'];
if( $do == 'follow' ) {
mysqli_query( $con, $followAction );
}
if( $do == 'unfollow' ) {
mysqli_query( $con, $unfollowAction );
}
$user_id3 = $_GET['user_id'];
header('Location:users.php?id='.$user_id3);
你没有做值.do值是跟随或取消关注
你试试死(mysql_error())在你的SQL查询中显示错误
mysqli_query( $con, $followAction ) or die(mysqli_error());