代码拉取完成,页面将自动刷新
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "cyberpunk";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接数据库失败: " . $conn->connect_error);
}
// 检查用户是否已登录
if (!isset($_SESSION['id'])) {
http_response_code(401);
echo json_encode(['error' => '用户未登录']);
exit;
}
$user_id = $_SESSION['id'];
$car_id = $_POST['car_id'];
$sql = "DELETE FROM user_cart WHERE user_id=? AND vehicle_id=?";
$stmt = $conn->prepare($sql);
if (!$stmt) {
http_response_code(500);
echo json_encode(['error' => '预处理 SQL 语句失败: ' . $conn->error]);
exit;
}
$stmt->bind_param("ii", $user_id, $car_id);
$stmt->execute();
$affected_rows = $stmt->affected_rows;
$stmt->close();
$conn->close();
$response = ['success' => ($affected_rows > 0)];
header('Content-Type: application/json');
echo json_encode($response);
exit;
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。