prepare("SELECT * FROM menu_items WHERE id IN ($placeholders)"); $stmt->execute($menu_item_ids); $db_items = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($db_items as $item) { $quantity = $_SESSION['cart'][$item['id']]; $item_total = $item['price'] * $quantity; $total_price += $item_total; $cart_items[] = [ 'id' => $item['id'], 'name' => $item['name'], 'price' => $item['price'], 'quantity' => $quantity, 'total' => $item_total ]; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $user_id = $_SESSION['user_id']; // Insert into orders table $stmt = db()->prepare("INSERT INTO orders (user_id, restaurant_id, total_price, status) VALUES (?, ?, ?, ?)"); $stmt->execute([$user_id, $restaurant_id, $total_price, 'pending']); $order_id = db()->lastInsertId(); // Insert into order_items table $stmt = db()->prepare("INSERT INTO order_items (order_id, menu_item_id, quantity, price) VALUES (?, ?, ?, ?)"); foreach ($cart_items as $item) { $stmt->execute([$order_id, $item['id'], $item['quantity'], $item['price']]); } // Clear the cart $_SESSION['cart'] = []; $_SESSION['cart_restaurant'] = null; // Redirect to a confirmation page header('Location: order_confirmation.php?id=' . $order_id); exit; } include 'header.php'; ?>

Checkout

Order Summary

Item Quantity Total
$

Total: $