为什么这不会向数据库添加内容


Why won't this add things to the database?

我正在尝试创建一个关注系统 - 有点像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是想要关注的用户。

您在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值是关注或取消关注

你尝试 die(mysql_error()) 在它附近显示 sql 查询中的错误

mysqli_query( $con, $followAction ) or die(mysqli_error());