<?php
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);

echo "Step 1: Session check<br>";
if (!isset($_SESSION['is_admin'])) {
    echo "ERROR: Not admin. Session: " . print_r($_SESSION, true);
    exit();
}
echo "Admin check passed<br>";

echo "Step 2: DB connection<br>";
require_once('auth/db.php');
if ($conn->connect_error) {
    echo "ERROR: DB connection failed: " . $conn->connect_error;
    exit();
}
echo "DB connected<br>";

echo "Step 3: Email parameter<br>";
$email = $_GET['email'] ?? '';
if (!$email) {
    echo "ERROR: No email provided";
    exit();
}
echo "Email: $email<br>";

echo "Step 4: Query prepare<br>";
$stmt = $conn->prepare("SELECT first_name FROM users WHERE email = ?");
if (!$stmt) {
    echo "ERROR: Prepare failed: " . $conn->error;
    exit();
}
echo "Prepare OK<br>";

echo "Step 5: Bind and execute<br>";
$stmt->bind_param("s", $email);
if (!$stmt->execute()) {
    echo "ERROR: Execute failed: " . $stmt->error;
    exit();
}
echo "Execute OK<br>";

echo "Step 6: Bind result<br>";
$stmt->bind_result($first_name);
if (!$stmt->fetch()) {
    echo "ERROR: Fetch failed or no data found";
    exit();
}
echo "Fetch OK. First name: $first_name<br>";

echo "ALL STEPS PASSED!";
$stmt->close();
?>