-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_cart.php
More file actions
31 lines (23 loc) · 859 Bytes
/
remove_cart.php
File metadata and controls
31 lines (23 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
session_start();
$conn = new mysqli("localhost", "root", "", "kutnik_store");
if ($conn->connect_error) {
die(json_encode(['success' => false, 'message' => 'Błąd połączenia z bazą danych.']));
}
$data = json_decode(file_get_contents("php://input"), true);
$item_id = $data['item_id'];
$rozmiar = $data['rozmiar'];
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
$query = "DELETE FROM koszyk WHERE user_id = ? AND item_id = ? AND rozmiar = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("iis", $user_id, $item_id, $rozmiar);
if ($stmt->execute()) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'message' => 'Nie udało się usunąć produktu.']);
}
$stmt->close();
}
$conn->close();
?>