I have implemented a friend system on the project I am working on, but now I am trying to add a "remove friend" function and not having the same luck.
If friends are accepted the value is 1, if pending it's 0.
I am getting no error messages, but when I check in my database it's removing the record of the friend relationship.
The function
function unfriend(str)
{
$("#Hint").html('Cancelling friendship..');
$.ajax({
type: "POST",
url: "parsers/friend_remove.php",
data: "type=uf&the_id=" +str,
success: function(msg){
$("#Hint").html(msg);
}
});
<div onclick="unfriend('<?php echo $fetch_invites->id; ?>');" style="cursor:pointer">
<input type="button" value="Remove as Friend">
</div>
The "friend_remove" php file.
<?php
include '../core/init.php';
$logged_id = $_POST['uid'];
$friend_id = $_POST['fid'];
$exist = mysql_query("SELECT 1 FROM friends WHERE `user_id`='{$logged_id}' AND `friend_id`='{$friend_id}'");
$exist = mysql_num_rows($exist);
if($exist > 0)
{
echo 'Friend request already sent!';
}else{
$remove = "DELETE FROM `friends` WHERE user_id='$logged_id' AND friend_id='$friend_id' OR user_id='$logged_id' AND friend_id='$logged_id'";
mysql_query($remove) or die(mysql_error());
echo "<input type='button' value='Friend removed'>";
}
?>