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

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

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

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

		    $sql = "SELECT * FROM login_gest WHERE mobile='$mobile' AND otp='$otp' ";
		    $result = mysqli_query($conn, $sql);

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

		if ($row['mobile'] === $mobile && $row['otp'] == $otp) {


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


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

				            $sql_order_table = "SELECT * FROM order_table WHERE customerMobile='$mobile_fetch' AND otp='$otp_fetch'";

				            $result_order_table = mysqli_query($conn, $sql_order_table);

				            if ($result_order_table && mysqli_num_rows($result_order_table) > 0) {
				                $order_item = mysqli_fetch_object($result_order_table);
				                echo json_encode(["status" => "success", "mobile" => $order_item->customerMobile]);

				            } else {
				                echo json_encode(["status" => "success", "message" => "অর্ডার তথ্য পাওয়া যায়নি।"]);
				            } exit;

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

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

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

?>
