gpt4 book ai didi

php - 删除好友脚本

转载 作者:行者123 更新时间:2023-11-29 13:39:22 25 4
gpt4 key购买 nike

我已经在我正在从事的项目上实现了好友系统,但现在我正在尝试添加“删除好友”功能,但没有同样的运气。

如果好友被接受,值为 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>

“friend_remove”php 文件。

    <?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'>";
}
?>

最佳答案

首先,您的好友 ID 的 $_POST 索引与您发布的 ajax 参数不同。所以它应该是 $_POST['the_id'] 而不是 $_POST['fid'] 。你应该按照帕特里克·柯林斯(Patric Collins)提到的那样包装你的sql

关于php - 删除好友脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18299457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com