<?php
// Include database connection
require_once 'shikanisha.kts.php'; // Update the path if necessary

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Collect POST data
    $shopname = mysqli_real_escape_string($conn, $_POST['shopname']);
    $location = mysqli_real_escape_string($conn, $_POST['location']);
    $street = mysqli_real_escape_string($conn, $_POST['street']);
    $address = mysqli_real_escape_string($conn, $_POST['address']);
    $pin = mysqli_real_escape_string($conn, $_POST['pin']);
    $contact1 = mysqli_real_escape_string($conn, $_POST['contact1']);
    $quote = mysqli_real_escape_string($conn, $_POST['quote']);
    $contact2 = isset($_POST['contact2']) ? mysqli_real_escape_string($conn, $_POST['contact2']) : '';

    // Validate mandatory fields
    if (empty($shopname) || empty($location) || empty($street) || empty($address) || empty($pin) || empty($contact1)) {
        echo json_encode(['status' => 'error', 'message' => 'Please fill in all required fields.']);
        exit;
    }

    // Insert into the database
    $sql = "INSERT INTO business_details (shop_name, location, street, address, pin, contact1, contact2,quote) 
            VALUES ('$shopname', '$location', '$street', '$address', '$pin', '$contact1', '$contact2', '$quote')";

    if (mysqli_query($conn, $sql)) {
        echo json_encode(['status' => 'success', 'message' => 'Business registered successfully!']);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Failed to register business.']);
    }
}
?>
