29 lines
891 B
PHP
29 lines
891 B
PHP
<?php
|
|
include 'db_connection.php';
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['username'])) {
|
|
echo json_encode(['success' => false, 'error' => 'Not logged in.']);
|
|
exit();
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$name = sanitize_input($_POST['name']);
|
|
$maps_link = sanitize_input($_POST['maps_link']);
|
|
|
|
$stmt = $db->prepare("INSERT INTO Restaurant (name, maps_link) VALUES (:name, :maps_link)");
|
|
$stmt->bindParam(':name', $name);
|
|
$stmt->bindParam(':maps_link', $maps_link);
|
|
|
|
if ($stmt->execute()) {
|
|
echo json_encode(['success' => true, 'message' => 'Restaurant added successfully!']);
|
|
exit();
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Error: ' . print_r($stmt->errorInfo(), true)]);
|
|
exit();
|
|
}
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Invalid request method.']);
|
|
exit();
|
|
}
|
|
?>
|