<?php
require_once __DIR__ . '/../../connect.php'; // Include the database connection

// Get the data from the request (e.g., from Flutter client)
$latitude = filterRequest("latitude");
$longitude = filterRequest("longitude");
$name = filterRequest("name");
$rate = filterRequest("rate");

// Assuming the `created_at` column is of type TIMESTAMP with the default value CURRENT_TIMESTAMP
$sql = "
  INSERT IGNORE INTO `places`(`latitude`, `longitude`, `name`, `rate`) 
  VALUES ('$latitude', '$longitude', '$name', '$rate')
";

$stmt = $con->prepare($sql);
$stmt->execute();

if ($stmt->rowCount() > 0) {
    // Print a success message
    jsonSuccess($message = 'Place inserted successfully');
} else {
    // Print a failure message for duplicate
    jsonSuccess($message = 'Duplicate place, no new entry added');
}
?>