Php 删除好友脚本

Php 删除好友脚本,php,mysql,Php,Mysql,我已经在我正在做的项目上实现了一个朋友系统,但是现在我试图添加一个“删除朋友”功能,而不是有同样的运气 如果接受好友,则值为1;如果挂起,则值为0 我没有收到任何错误消息,但当我签入数据库时,它会删除好友关系的记录 功能 function unfriend(str) { $("#Hint").html('Cancelling friendship..'); $.ajax({ type: "POST", url

我已经在我正在做的项目上实现了一个朋友系统,但是现在我试图添加一个“删除朋友”功能,而不是有同样的运气

如果接受好友,则值为1;如果挂起,则值为0

我没有收到任何错误消息,但当我签入数据库时,它会删除好友关系的记录

功能

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>
函数unfriend(str)
{
$(“#提示”).html('取消友谊…);
$.ajax({
类型:“POST”,
url:“parsers/friend_remove.php”,
数据:“type=uf&the_id=“+str,
成功:功能(msg){
$(“#提示”).html(msg);
}
});
看起来像

$remove = "DELETE FROM `friends` WHERE user_id='$logged_id' AND friend_id='$friend_id' OR user_id='$logged_id' AND friend_id='$logged_id'"
永远不会匹配表中的任何内容(除非我误解了SQL中运算符优先级的工作原理)。请尝试以下操作:

$remove = "DELETE FROM `friends` WHERE (user_id='$logged_id' AND friend_id='$friend_id') OR (user_id='$logged_id' AND friend_id='$logged_id')"

编辑:假设您在问题中的意思是“不从数据库中删除记录”。

首先,您发布的朋友id的$\u POST索引与您发布的ajax参数不同。 因此,它应该是
$\u POST['the_id']
而不是
$\u POST['fid']
。并且您应该按照Patric Collins所提到的那样包装sql

$remove = "DELETE FROM 'friends' WHERE (user_id='$logged_id' AND friend_id='$friend_id') OR (user_id='$friend_id' AND friend_id='$logged_id')";

如果您只想删除这两个关系(用户->朋友,朋友->用户)

您正在使用且应该使用的可能重复项。您还容易受到现代API的攻击,因为它会使您更容易使用。正如第一篇帖子所说……我没有收到任何错误消息,但当我签入数据库时,它会删除朋友关系的记录。谢谢您的回答,但仍然无法正常工作:(朋友关系在数据库中保持完整。
$remove=“从“朋友”中删除,其中(用户\u id='$logged\u id'和朋友\u id='$friend\u id')或(用户\u id='$friend\u id'和朋友\u id='$logged\u id')”;
?where的第二部分我不清楚您要检查什么?有两个位置,请求可以由用户或朋友发送,因此用户信息可以在用户行和朋友行中。
$remove = "DELETE FROM 'friends' WHERE (user_id='$logged_id' AND friend_id='$friend_id') OR (user_id='$friend_id' AND friend_id='$logged_id')";