prepare("SELECT id FROM restaurants WHERE user_id = ?"); $stmt->execute([$_SESSION['user_id']]); $restaurant = $stmt->fetch(); if (!$restaurant) { header('Location: ../index.php'); exit; } $restaurant_id = $restaurant['id']; // Get the menu item and verify it belongs to the correct restaurant $stmt = $pdo->prepare("SELECT * FROM menu_items WHERE id = ? AND restaurant_id = ?"); $stmt->execute([$menu_item_id, $restaurant_id]); $item = $stmt->fetch(); if (!$item) { // If the item doesn't exist or doesn't belong to this owner, redirect header('Location: menu.php'); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name'] ?? ''; $description = $_POST['description'] ?? ''; $price = $_POST['price'] ?? ''; $promotion_id = $_POST['promotion_id'] ?? null; if ($name && $price) { $stmt = $pdo->prepare("UPDATE menu_items SET name = ?, description = ?, price = ?, promotion_id = ? WHERE id = ? AND restaurant_id = ?"); $stmt->execute([$name, $description, $price, $promotion_id, $menu_item_id, $restaurant_id]); header('Location: menu.php'); exit; } else { $error = "Name and price are required."; } } $stmt = $pdo->prepare("SELECT * FROM special_promotions"); $stmt->execute(); $promotions = $stmt->fetchAll(); ?>

Edit Menu Item

Cancel