-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
47 lines (41 loc) · 1.59 KB
/
cart.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
session_start();
include_once("./Includes/connection.php");
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit'])) {
$itemId = $_POST['itemId'];
$quantity = $_POST['quantityNumber'];
$size = $_POST['sizeOfItem'];
// Fetch item details including price and image path from the database
$db = new Connection();
$conn = $db->getConnection();
$stmt = $conn->prepare("SELECT price, productName, category, images FROM clothing_items WHERE id = :itemId");
$stmt->bindParam(':itemId', $itemId);
$stmt->execute();
$item = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$item) {
// If item not found in the first table, try the second table
$stmt = $conn->prepare("SELECT price, productName, category, images FROM clothing_items_bridal_wear WHERE id = :itemId");
$stmt->bindParam(':itemId', $itemId);
$stmt->execute();
$item = $stmt->fetch(PDO::FETCH_ASSOC);
}
if ($item) {
$price = $item['price'];
$imagePath = $item['images']; // Corrected variable name
// Add item to the cart session variable along with size and image path
$_SESSION['cart'][] = array(
'itemId' => $itemId,
'quantity' => $quantity,
'size' => $size,
'price' => $price,
'productName' => $item['productName'],
'category' => $item['category'],
'images' => explode(',', $item['images']) // Store all images in an array
);
header('Location: display_cart.php');
exit;
} else {
echo "Item not found.";
}
}
?>