-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_restaurant.php
More file actions
112 lines (99 loc) · 4.28 KB
/
add_restaurant.php
File metadata and controls
112 lines (99 loc) · 4.28 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
// Start the session
session_start();
// Check if the owner is logged in
if (!isset($_SESSION["login_sess"])) {
header("Location: owner_login.php");
exit;
}
// Include database connection
require_once("database/config.php");
// Handle form submission
if (isset($_POST['add_restaurant'])) {
// Get the form data and sanitize inputs
$name = mysqli_real_escape_string($dbc, $_POST['name']);
$location = mysqli_real_escape_string($dbc, $_POST['location']);
$rating = mysqli_real_escape_string($dbc, $_POST['rating']);
$famousfor = mysqli_real_escape_string($dbc, $_POST['famousfor']);
$maplink = mysqli_real_escape_string($dbc, $_POST['maplink']);
// Retrieve owner_id from session
if (isset($_SESSION["owner_id"])) {
$owner_id = $_SESSION["owner_id"];
// Check if the owner_id exists in the owners table
$checkOwnerQuery = "SELECT * FROM owners WHERE id = '$owner_id'";
$result = mysqli_query($dbc, $checkOwnerQuery);
if (mysqli_num_rows($result) == 0) {
die("The owner ID does not exist in the owners table.");
}
// Insert data into the restaurants table
$query = "INSERT INTO restaurants (name, location, rating, famousfor, maplink, owner_id)
VALUES ('$name', '$location', '$rating', '$famousfor', '$maplink', '$owner_id')";
if (mysqli_query($dbc, $query)) {
// Redirect to the same page with a success message
header("Location: add_restaurant.php?success=restaurant_added");
exit;
} else {
echo "Error: " . mysqli_error($dbc); // Output any database error
}
} else {
die("Owner not logged in. Please log in as an owner.");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Restaurant</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Auto redirect after success message -->
<?php if (isset($_GET['success']) && $_GET['success'] == 'restaurant_added'): ?>
<script>
// Wait 3 seconds, then redirect to the dashboard
setTimeout(function(){
window.location.href = 'owner_login.php';
}, 3000);
</script>
<?php endif; ?>
</head>
<body class="bg-light">
<div class="container mt-5">
<h1 class="text-center">Add New Restaurant</h1>
<!-- Display success message -->
<?php if (isset($_GET['success']) && $_GET['success'] == 'restaurant_added'): ?>
<div class="alert alert-success">
Restaurant added successfully! Redirecting to dashboard...
</div>
<?php endif; ?>
<form action="add_restaurant.php" method="POST" class="mt-4">
<div class="mb-3">
<label for="name" class="form-label">Restaurant Name</label>
<input type="text" name="name" id="name" class="form-control" required>
</div>
<div class="mb-3">
<label for="location" class="form-label">Location</label>
<input type="text" name="location" id="location" class="form-control" required>
</div>
<div class="mb-3">
<label for="rating" class="form-label">Rating</label>
<input type="number" name="rating" id="rating" class="form-control" min="1" max="5" required>
</div>
<div class="mb-3">
<label for="famousfor" class="form-label">Famous For</label>
<input type="text" name="famousfor" id="famousfor" class="form-control" required>
</div>
<div class="mb-3">
<label for="maplink" class="form-label">Google Maps Link</label>
<input type="url" name="maplink" id="maplink" class="form-control" required>
</div>
<div class="text-center">
<button type="submit" name="add_restaurant" class="btn btn-primary">Add Restaurant</button>
</div>
</form>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>