爲什麼不能使用此代碼?我想在添加之前檢查用戶是否已經是朋友。檢查朋友關係是否已經存在
function addFriend()
{
global $userid, $friendid;
$check = mysql_query("SELECT * FROM friends WHERE userid = $userid AND friendid = $friendid");
if (mysql_num_rows($check) == 1)
{
exit("Youre already friend with this user");
}
else
{
$sql = "INSERT INTO friends (userid, friendid) VALUES ($userid, $friendid)";
mysql_query($sql);
if ($sql)
echo "Success";
else
echo "Failure";
}
}