<?php
require_once "config.php";

if($_SERVER['REQUEST_METHOD'] === 'POST') {
    $property_id = $_POST['admin_property_id'];
    $location = $_POST['location'];
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];

    $stmt = $conn->prepare("INSERT INTO admin_adverts (admin_property_id, location, start_date, end_date) VALUES (?, ?, ?, ?)");
    $stmt->bind_param("isss", $property_id, $location, $start_date, $end_date);

    if($stmt->execute()){
        echo "<script>alert('Advert created successfully'); window.location.href='admin_dash.php';</script>";
    } else {
        echo "<script>alert('Error creating advert'); window.history.back();</script>";
    }

    $stmt->close();
    $conn->close();
}
?>
