<?php
include 'config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $table = $_POST["table"];
    $email = $_POST["email"];

$admin_username = $_POST['admin_username']; // POST থেকে username নেওয়া
    $admin_password = $_POST['admin_password'];

    // Prepared statement — username ব্যবহার করবে (email নয়)
    $admin_stmt = $conn->prepare("SELECT 1 FROM admin WHERE username = ? AND password = ?");
    $admin_stmt->bind_param("ss", $admin_username, $admin_password);
    $admin_stmt->execute();
    $admin_result = $admin_stmt->get_result();

    if ($admin_result->num_rows === 0) {
        http_response_code(403);
        echo json_encode([
            "status" => "error",
            "message" => "Access Denied"
        ], JSON_PRETTY_PRINT);
        $admin_stmt->close();
        $conn->close();
        exit();
    }
    $admin_stmt->close();





    $sql = "SELECT * FROM $table WHERE email = '$email'";
    $result = $conn->query($sql);

    $json_data = array();

    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            $json_data[] = $row;
        }

        echo json_encode($json_data);
    } else {
        echo "No Data Found";
    }

    $conn->close();
} else {
    echo "Invalid Request Method";
}
?>