<?php
include("configa.php");

header('Content-Type: application/json; charset=utf-8'); // ✅ JSON header সেট

$response = ["status" => "error", "message" => "অজানা ত্রুটি ঘটেছে।"];

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $first_name = mysqli_real_escape_string($conn, $_POST['first_name'] ?? '');
    $last_name  = mysqli_real_escape_string($conn, $_POST['last_name'] ?? '');
    $mobile     = mysqli_real_escape_string($conn, $_POST['mobile'] ?? '');
    $division   = mysqli_real_escape_string($conn, $_POST['division'] ?? '');
    $district   = mysqli_real_escape_string($conn, $_POST['district'] ?? '');
    $upazila    = mysqli_real_escape_string($conn, $_POST['upazila'] ?? '');
    $union      = mysqli_real_escape_string($conn, $_POST['union'] ?? '');
    $shopName   = mysqli_real_escape_string($conn, $_POST['shopName'] ?? '');
    $address    = mysqli_real_escape_string($conn, $_POST['address'] ?? '');
    $id_no      = mysqli_real_escape_string($conn, $_POST['id_no'] ?? '');

    if (!empty($first_name) && !empty($mobile) && !empty($shopName)) {








        // $sql = "INSERT INTO seller 
        //         (id_no, first_name, last_name, mobile, division, district, upazila, up, shopName, address) 
        //         VALUES 
        //         ('$id_no','$first_name', '$last_name', '$mobile', '$division', '$district', '$upazila', '$union', '$shopName', '$address')";



        $sql = "UPDATE seller SET 
            first_name = '$first_name',
            last_name  = '$last_name',
            mobile     = '$mobile',
            division   = '$division',
            district   = '$district',
            upazila    = '$upazila',
            up         = '$union',
            shopName   = '$shopName',
            address    = '$address'
        WHERE id_no = '$id_no'";







        if (mysqli_query($conn, $sql)) {
            $response = ["status" => "success", "message" => "✅ ডেটা সফলভাবে সংরক্ষণ করা হয়েছে!"];
        } else {
            $response = ["status" => "error", "message" => "❌ ডাটাবেজ ত্রুটি: " . mysqli_error($conn)];
        }
    } else {
        $response = ["status" => "error", "message" => "⚠️ অনুগ্রহ করে নাম, মোবাইল ও দোকানের নাম পূরণ করুন।"];
    }
}

mysqli_close($conn);
echo json_encode($response, JSON_UNESCAPED_UNICODE); // ✅ সবসময় JSON রিটার্ন হবে
exit;
?>



