这是包含的 PHP 文件:
<?php
session_start();
include("../includes/dbcxnfunction.inc");
$billid = $_POST['billid'];
$userid = $_SESSION['userid'];
$query = "IF EXISTS ( SELECT * FROM favoritebills WHERE userid = '$userid' AND billid = '$billid' )
DELETE FROM favoritebills WHERE userid = '$userid' and billid = '$billid'
ELSE
INSERT INTO favoritebills (userid,billid) VALUES($userid,$billid) ";
$result = mysqli_query(dbcxn('bill'),$query)
or exit("Couldn't execute query for favorites");
if($result)
{
$request = "true";
}
else
{
$request = "false";
}
echo $request;
?>
查询是:
"IF EXISTS ( SELECT * FROM favoritebills WHERE userid = '$userid' AND billid = '$billid' )
DELETE FROM favoritebills WHERE userid = '$userid' and billid = '$billid'
ELSE
INSERT INTO favoritebills (userid,billid) VALUES($userid,$billid) ";
userid 和 billid 都是整数。
这是我的网络标签:
在我的 .js 文件中,我有console.log(response);
控制台正在记录“无法执行收藏夹查询”