<?php
include 'config.php';
header("Content-Type: application/json");

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $image1 = $_POST['image1'] ?? "";
    $image2 = $_POST['image2'] ?? "";
    $image3 = $_POST['image3'] ?? "";
    $image4 = $_POST['image4'] ?? "";
    $image5 = $_POST['image5'] ?? "";
    $image6 = $_POST['image6'] ?? "";

    // Table না থাকলে তৈরি করো
    $tableCheck = $conn->query("SHOW TABLES LIKE 'sliders'");
    if ($tableCheck->num_rows == 0) {
        $create = "CREATE TABLE sliders (
            id INT AUTO_INCREMENT PRIMARY KEY,
            image1 TEXT,
            image2 TEXT,
            image3 TEXT,
            image4 TEXT,
            image5 TEXT,
            image6 TEXT
        )";
        $conn->query($create);
    }

    // পুরাতন ডেটা ডিলিট করো
    $conn->query("DELETE FROM sliders");

    // নতুন ডেটা ইনসার্ট করো
    $stmt = $conn->prepare("INSERT INTO sliders (image1, image2, image3, image4, image5, image6) VALUES (?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("ssssss", $image1, $image2, $image3, $image4, $image5, $image6);
    $stmt->execute();

    echo json_encode(["success" => true, "message" => "Images saved successfully"]);

} else {
    echo json_encode(["success" => false, "message" => "Invalid request method"]);
}
?>