<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

include "confing.php"; 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $vendor_id      = $_POST['vendor_id'];
    $vendor_name    = $_POST['vendor_name'];
    $service_name   = $_POST['service_name'];
    $booking_date   = $_POST['booking_date'];
    $booking_time   = $_POST['booking_time'];
    $vendor_long    = $_POST['vendor_long'];
    $vendor_lat     = $_POST['vendor_lat'];
    $vendor_image   = $_POST['vendor_image'];
    $service_charge = $_POST['service_charge'];
    $vendor_address = $_POST['vendor_address'];
    $user_id        = $_POST['user_id'];
     $user_latitude = $_POST['user_latitude'];
    $user_longitude = $_POST['user_longitude'];
    $address = $_POST['address'];

    
    $current_date = date("d-m-Y");
    $sql = "INSERT INTO booking (
                vendor_id, vendor_name, service_name, booking_date, booking_time,
                vendor_long, vendor_lat, vendor_image, service_charge, vendor_address, user_id, cureent_date,user_latitude,user_longitude,address
            ) VALUES (
                '$vendor_id', '$vendor_name', '$service_name', '$booking_date', '$booking_time',
                '$vendor_long', '$vendor_lat', '$vendor_image', '$service_charge', '$vendor_address', '$user_id', '$current_date', '$user_latitude', '$user_longitude', '$address'
            )";

    if (mysqli_query($conn, $sql)) {
        echo json_encode(["status" => "success", "message" => "Booking inserted successfully."]);
    } else {
        echo json_encode(["status" => "error", "message" => "Insert failed: " . mysqli_error($conn)]);
    }
} else {
    echo json_encode(["status" => "error", "message" => "Invalid Request"]);
}
?>