<?php
session_start();
require_once __DIR__ . '/auth/db.php';

echo "Session email: " . ($_SESSION['email'] ?? 'NOT SET') . "<br>";
echo "DB connection: " . ($conn->connect_error ? 'FAILED' : 'OK') . "<br>";

// Test the query
$email = $_SESSION['email'] ?? 'test@test.com';
$milestone = 5;

$check = $conn->prepare("SELECT 1 FROM completed_tasks WHERE user_email=? AND task_name=?");
if ($check === false) {
    echo "Prepare failed: " . $conn->error;
    exit;
}

$task_name = "invite_$milestone";
$check->bind_param("ss", $email, $task_name);
$check->execute();
$check->bind_result($found);
$result = $check->fetch();
$check->close();

echo "Query executed successfully<br>";
echo "Found: " . ($result ? 'YES' : 'NO');
?>