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

if (!isset($_SESSION['mobile'])) {
    header('Location: http://localhost/online_goods/index.php');
    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");

// $result = mysqli_query($conn, "SELECT * FROM order_table WHERE category_name = '$categoryName' 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"]);
    }
}
?>
