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

// POST method theke email niye asha
$email = $_POST['email'] ?? '';

if (empty($email)) {
    echo json_encode([
        'success' => false,
        'message' => 'Email parameter missing'
    ]);
    exit;
}

// Prepared statement use kore SQL query
$stmt = $conn->prepare("SELECT * FROM statistics WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();

$result = $stmt->get_result();
$rows = [];

while ($row = $result->fetch_assoc()) {
    $rows[] = $row;
}

// Response JSON
echo json_encode([
    'success' => true,
    'data' => $rows
]);

$stmt->close();
$conn->close();
?>