<?php
require_once 'config.php';

echo "<h2>Database Debug - Users Table</h2>";

// Check if users table exists
$result = mysqli_query($link, "SHOW TABLES LIKE 'users'");
if (mysqli_num_rows($result) > 0) {
    echo "<p>✅ Users table exists</p>";
    
    // Get all users
    $result = mysqli_query($link, "SELECT id, username, usernumber, reg_date FROM users ORDER BY id DESC LIMIT 10");
    if ($result && mysqli_num_rows($result) > 0) {
        echo "<h3>Recent Users:</h3>";
        echo "<table border='1' style='border-collapse: collapse; margin: 10px 0;'>";
        echo "<tr><th>ID</th><th>Username</th><th>User Number</th><th>Registration Date</th></tr>";
        
        while ($row = mysqli_fetch_assoc($result)) {
            echo "<tr>";
            echo "<td>" . htmlspecialchars($row['id']) . "</td>";
            echo "<td>" . htmlspecialchars($row['username']) . "</td>";
            echo "<td>" . htmlspecialchars($row['usernumber']) . "</td>";
            echo "<td>" . htmlspecialchars($row['reg_date']) . "</td>";
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "<p>❌ No users found in database</p>";
    }
} else {
    echo "<p>❌ Users table does not exist</p>";
}

// Check session
session_start();
echo "<h3>Current Session Data:</h3>";
echo "<pre>" . print_r($_SESSION, true) . "</pre>";

mysqli_close($link);
?>