Now I want to make unfollow button if some one already followed then don't show follow button the browser should be show unfollow button instead of follow button like twitter. I just tested (Unfollow button is appear) there but not working perfectly . it because when i online from (user1) and follow some one it work and follow button changed to unfollow but when i online from (user2) , want to follow same person which followed by (user1) .. From (user2) timeline it showing already followed(Button) please check the code
if(isset($_POST['follow']))
{
$checkFollow=mysqli_query($con,"SELECT follower_id FROM follower WHERE user_id='$userid'");
if(mysqli_num_rows($checkFollow)==0)
{
$follow=mysqli_query($con,"INSERT INTO follower(user_id,follower_id) VALUES ('$userid','$followerid')");
echo "You Followed";
}
else
{
echo "Sorry! You already followed this profile";
}
$isFollowing=True;
}
$checkFollow=mysqli_query($con,"SELECT follower_id FROM follower WHERE user_id='$userid'");
if(mysqli_num_rows($checkFollow))
{
$isFollowing=True;
}
}
HTML Code is
<form action="<?php echo $username;?>" method="post">
<?php
if($isFollowing)
{
echo "<input type='submit' value='Unfollow' name='unfollow' class='unfollow_button'>";
}
else
{
echo "<input type='submit' value='Follow' name='follow' class='unfollow_button'>";
}
?>
</form>