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

// ✅ সেশন না থাকলে JSON দিয়ে জানাও
if (!isset($_SESSION['mobile'])) {
    echo json_encode(['status' => 'no_session']);
    exit;
}


$mobile = $_SESSION['mobile'];
$otp    = $_SESSION['otp'];


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

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

    $result = mysqli_query($conn, "SELECT * FROM order_table WHERE customerMobile = '$mobile' and otp = '$otp'  ORDER BY id DESC");

    $orders = [];

    while ($row = mysqli_fetch_assoc($result)) {
        $orders[] = $row;
    }

    if (!empty($orders)) {
        echo json_encode(["status" => "success", "orders" => $orders]);
    } else {
        echo json_encode(["status" => "error", "message" => "No data found"]);
    }
}
?>
