<?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']);


$product_name = mysqli_real_escape_string($conn, $_POST['product_name']);
$item = mysqli_real_escape_string($conn, $_POST['item']);
$gks = mysqli_real_escape_string($conn, $_POST['gks']);
$seller = mysqli_real_escape_string($conn, $_POST['seller']);
$currentPrice = mysqli_real_escape_string($conn, $_POST['currentPrice']);
$price = mysqli_real_escape_string($conn, $_POST['price']);
$discount = mysqli_real_escape_string($conn, $_POST['discount']);
$quantity = mysqli_real_escape_string($conn, $_POST['quantity']);
$weight = mysqli_real_escape_string($conn, $_POST['weight']);
$description = mysqli_real_escape_string($conn, $_POST['description']);
$specification = mysqli_real_escape_string($conn, $_POST['specification']);
$vendorInfo = mysqli_real_escape_string($conn, $_POST['vendorInfo']);
$customerReview = mysqli_real_escape_string($conn, $_POST['customerReview']);
$questionAnswer = mysqli_real_escape_string($conn, $_POST['questionAnswer']);







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

    $otp = $_SESSION['otp'];
    // $otp = isset($_SESSION['otp']) ? $_SESSION['otp'] : '';

$sql = "INSERT INTO order_table (
    category_name, category_picture, product_name, item, gks, seller,
    current_price, price, discount, quantity, weight, description,
    specification, vendor_info, customer_review, question_and_answer,
    customerMobile, otp
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssssddddssssssss",
    $categoryName, $categoryPicture, $product_name, $item, $gks, $seller,
    $currentPrice, $price, $discount, $quantity, $weight, $description,
    $specification, $vendorInfo, $customerReview, $questionAnswer,
    $mobile, $otp
);

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



}
?>
