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

// JSON রেসপন্স নিশ্চিত করার জন্য হেডার
header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $username = mysqli_real_escape_string($conn, $_POST['username']);
    $password = mysqli_real_escape_string($conn, $_POST['password']);

    $sql = "SELECT * FROM seller WHERE username='$username' AND password='$password'";
    $result = mysqli_query($conn, $sql);

    if ($result && mysqli_num_rows($result) === 1) {
        $row = mysqli_fetch_assoc($result);

        if ($row['username'] === $username && $row['password'] == $password) {

       
            // ✅ সেশন সেট
            $_SESSION['username'] = $row['username'];
            $_SESSION['password'] = $row['password'];
            $_SESSION['id_no'] = $row['id_no'];


            $_SESSION['first_name'] = $row['first_name'];
            $_SESSION['last_name'] = $row['last_name'];


            $_SESSION['shopName'] = $row['shopName'];



            $_SESSION['up'] = $row['up'];
            $_SESSION['upazila'] = $row['upazila'];
            $_SESSION['district'] = $row['district'];          
            $_SESSION['division'] = $row['division'];


            $_SESSION['address'] = $row['address'];










      


            echo json_encode([
                     "status" => "success",
                     "username" => $_SESSION['username'],
                     "password" => $_SESSION['password'],
                     "message" => "অর্ডার তথ্য পাওয়া গিয়েছে।"
                 ]);

        } else {
            echo json_encode([
                "status" => "error",
                "message" => "password বা মোবাইল নম্বর সঠিক নয়।"
            ]);
            exit;
        }

    } else {
        echo json_encode([
            "status" => "error",
            "message" => "পাসওয়ার্ড বা মোবাইল নম্বর মেলেনি।"
        ]);
        exit;
    }

} else {
    echo json_encode([
        "status" => "error",
        "message" => "Invalid request method."
    ]);
    exit;
}
?>
