I have this problem: on the following code i made a form with a condition, where if the "profileid" is in array friends then print the button "add to friends" else "remove to friends" but the second condition don't work it don't prints anything and when i load the page for the first time, there is ever the button "add to friends" either if there's already the "friend id" in the array.
Here is my code:
<?php
$userid = $_SESSION['userid'];
$profileid = $_SESSION['profileID'];
$compressed_friends=mysql_query("SELECT friends FROM users WHERE id LIKE '$userid'");
$friends = explode (',',$compressed_friends);
if(isset($_POST['addFriends']))
{
$compressed_friends=$profileid.','.$compressed_friends;
mysql_query("UPDATE users SET friends='$compressed_friends' WHERE id='$userid'");
}
elseif(isset($_POST['removeFriends']))
{
array_filter($friends,$profileid);
$compressed_friends=implode(',', $friends);
mysql_query("UPDATE users SET friends='$compressed_friends' WHERE id='$userid'");
}
else
{
?>
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<?php
if(!in_array($profileid, $friends))
{
echo' <button type="submit" name="addFriends" class="btn btn-primary col-lg-3">Add to friends</button>';
}
elseif(in_array($profileid, $friends))
{
echo '<button type="submit" name="removeFriends" class="btn btn-danger col-lg-3">Remove to Friends</button>';
}
?>
</form>
<?php } ?>