I am trying to make a follow system - a bit like what Twitter has. For some reason, nothing is added to the database when I click the 'follow' button. How can I fix this?
The code I have is:
$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>";
}
In the follow_action.php document, I have this code:
$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);
The follow table in the database has these rows: id, user_one and user_two - with user_one being the logged in user and user_two the user who is wanted to be followed.