id|addedby|requested | status
1 | 6 | 4 | accepted
2 | 4 | 6 | accepted
你可以看到两行......用户6和4 我的问题是 。 如果用户想要取消/删除用户,则只有一行被id删除 我想删除这两行,以便用户从双方都不友好。
我从ajax传递了两个变量,它的工作正常,值成功传递。
会话ID = 4; user id = 6;
<?php
session_start()
$sess=$_SESSION['SESS_MEMBER_ID'];
include("config.php");
if($_POST['id'])
{
$id=$_POST['id'];
$id = mysql_escape_String($id);
$sql = "delete from friends WHERE
(addedby='$sess' and requested='$id')
OR (addedby='$id' and requested='$sess')";
mysql_query($sql);
}
?>
...连
<?php
session_start()
$sess=$_SESSION['SESS_MEMBER_ID'];
include("config.php");
if($_POST['id'])
{
$id=$_POST['id'];
$id = mysql_escape_String($id);
$sql = "delete from friends WHERE
(addedby='4' and requested='6')
OR (addedby='6' and requested='4')";
mysql_query($sql);
}
?>
甚至
<?php
session_start()
$sess=$_SESSION['SESS_MEMBER_ID'];
include("config.php");
if($_POST['id'])
{
$id=$_POST['id'];
$id = mysql_escape_String($id);
$sql = "delete from friends WHERE`enter code here`
(addedby=6 and requested=4)
OR (addedby=4 and requested=6)";
mysql_query($sql);
}
?>
答案 0 :(得分:3)
我假设您要删除单个 SQL查询中的两行。
在这种情况下,只需在where
子句中指定两个条件:
DELETE FROM whatever_tablename
WHERE
(addedby=6 and requested=4)
OR (addedby=4 and requested=6)
答案 1 :(得分:2)
您可以使用伪造的代码,因为您没有提供足够的信息
DELETE FROM [table]
WHERE (addedBy = [addedByVar] AND requested = [requestedVar])
OR
(addedBy = [requestedVar] AND requested = [addedByVar])