Rippchen/add_restaurant.php
2025-04-15 20:29:16 +02:00

46 lines
1.3 KiB
PHP

<?php
include 'db_connection.php';
session_start();
if (!isset($_SESSION['username'])) {
header("Location: login.php"); // Redirect if not logged in
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = sanitize_input($_POST['name']);
$maps_link = sanitize_input($_POST['maps_link']);
$sql = "INSERT INTO Restaurant (name, maps_link) VALUES ('$name', '$maps_link')";
if ($conn->query($sql) === TRUE) {
$restaurant_success = "Restaurant added successfully!";
} else {
$restaurant_error = "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Add Restaurant</title>
</head>
<body>
<h2>Add New Restaurant</h2>
<?php if (isset($restaurant_error)): ?>
<p style="color:red;"><?php echo $restaurant_error; ?></p>
<?php endif; ?>
<?php if (isset($restaurant_success)): ?>
<p style="color:green;"><?php echo $restaurant_success; ?></p>
<?php endif; ?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Name: <input type="text" name="name" required><br><br>
Maps Link: <input type="text" name="maps_link"><br><br>
<input type="submit" value="Add Restaurant">
</form>
<p><a href="index.php">Back to Dashboard</a></p>
</body>
</html>