<?php
session_start();

if (!isset($_SESSION['mobile'])) {
    header('Location: http://localhost/online_goods/index.php');
    exit;
}

include("configa.php");

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

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

    // সেশন থেকে মোবাইল ও otp নিচ্ছি (যদি সেগুলো ইনপুট থেকে না আসে)
    $mobile = $_SESSION['mobile'];
    $otp = isset($_SESSION['otp']) ? $_SESSION['otp'] : '';

    $sql = "INSERT INTO order_table (category_name, category_picture, customerMobile, otp)
            VALUES ('$categoryName', '$categoryPicture', '$mobile', '$otp')";

    if (mysqli_query($conn, $sql)) {
        $_SESSION['has_order'] = true;
        echo json_encode(["status" => "success", "message" => "কার্ডে যোগ করা হয়েছে!"]);
    } else {
        echo json_encode(["status" => "error", "message" => "ত্রুটি হয়েছে: " . mysqli_error($conn)]);
    }
}
?>
