= 1 && $rating <= 5) { try { $insert_stmt = db()->prepare("INSERT INTO ratings (restaurant_id, user_id, rating, review) VALUES (:restaurant_id, :user_id, :rating, :review)"); $insert_stmt->bindParam(':restaurant_id', $restaurant_id, PDO::PARAM_INT); $insert_stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $insert_stmt->bindParam(':rating', $rating, PDO::PARAM_INT); $insert_stmt->bindParam(':review', $review, PDO::PARAM_STR); $insert_stmt->execute(); // Redirect to the same page to prevent form resubmission header("Location: menu.php?id=$restaurant_id&rated=true"); exit; } catch (PDOException $e) { $submit_error = "Error submitting your review. Please try again."; // In a real app, you'd log this error. } } else { $submit_error = "Please select a rating between 1 and 5."; } } require_once 'header.php'; try { // Fetch restaurant details $stmt = db()->prepare("SELECT name, image_url, cuisine FROM restaurants WHERE id = :id"); $stmt->bindParam(':id', $restaurant_id, PDO::PARAM_INT); $stmt->execute(); $restaurant = $stmt->fetch(PDO::FETCH_ASSOC); // Fetch menu items $menu_stmt = db()->prepare("SELECT id, name, description, price, image_url FROM menu_items WHERE restaurant_id = :restaurant_id"); $menu_stmt->bindParam(':restaurant_id', $restaurant_id, PDO::PARAM_INT); $menu_stmt->execute(); $menu_items = $menu_stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch ratings and calculate average $ratings_stmt = db()->prepare("SELECT r.rating, r.review, r.created_at, u.name as user_name FROM ratings r JOIN users u ON r.user_id = u.id WHERE r.restaurant_id = :restaurant_id ORDER BY r.created_at DESC"); $ratings_stmt->bindParam(':restaurant_id', $restaurant_id, PDO::PARAM_INT); $ratings_stmt->execute(); $ratings = $ratings_stmt->fetchAll(PDO::FETCH_ASSOC); $average_rating = 0; if (count($ratings) > 0) { $total_rating = 0; foreach ($ratings as $r) { $total_rating += $r['rating']; } $average_rating = round($total_rating / count($ratings), 1); } } catch (PDOException $e) { echo "

Error fetching restaurant data.

"; require_once 'footer.php'; exit; } ?>

( reviews)
Image of <?php echo htmlspecialchars($restaurant['name']); ?>

Menu

<?php echo htmlspecialchars($item['name']); ?>

$

This restaurant has no menu items yet.


Reviews & Ratings

Leave a Review
Thank you for your review!
Log in to leave a review.

This restaurant has no reviews yet. Be the first!

Restaurant not found.