Search Results for ""
- -No restaurants found.
- - -diff --git a/admin/add_restaurant.php b/admin/add_restaurant.php index 729ddb6c..98e35076 100644 --- a/admin/add_restaurant.php +++ b/admin/add_restaurant.php @@ -8,19 +8,42 @@ if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== tru exit; } +$pdo = db(); + +// Fetch all cuisines +$cuisines_stmt = $pdo->query("SELECT * FROM cuisines ORDER BY name ASC"); +$cuisines = $cuisines_stmt->fetchAll(); + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name'] ?? ''; - $cuisine = $_POST['cuisine'] ?? ''; + $description = $_POST['description'] ?? ''; $image_url = $_POST['image_url'] ?? ''; + $selected_cuisines = $_POST['cuisines'] ?? []; - if ($name && $cuisine) { - $pdo = db(); - $stmt = $pdo->prepare("INSERT INTO restaurants (name, cuisine, image_url) VALUES (?, ?, ?)"); - $stmt->execute([$name, $cuisine, $image_url]); - header('Location: index.php'); - exit; + if ($name && !empty($selected_cuisines)) { + try { + $pdo->beginTransaction(); + + // Insert into restaurants table + $stmt = $pdo->prepare("INSERT INTO restaurants (name, description, image_url) VALUES (?, ?, ?)"); + $stmt->execute([$name, $description, $image_url]); + $restaurant_id = $pdo->lastInsertId(); + + // Insert into restaurant_cuisines table + $cuisine_stmt = $pdo->prepare("INSERT INTO restaurant_cuisines (restaurant_id, cuisine_id) VALUES (?, ?)"); + foreach ($selected_cuisines as $cuisine_id) { + $cuisine_stmt->execute([$restaurant_id, $cuisine_id]); + } + + $pdo->commit(); + header('Location: index.php'); + exit; + } catch (Exception $e) { + $pdo->rollBack(); + $error = "Error adding restaurant: " . $e->getMessage(); + } } else { - $error = "Name and cuisine are required."; + $error = "Name and at least one cuisine are required."; } } ?> @@ -38,8 +61,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
| ID | +Name | +Actions | +
|---|---|---|
| + | + | + + | +