<?php
// check_structure.php - DELETE AFTER CHECKING!
require_once 'includes/db.php'; // or whatever your config file is named

echo "<h2>Database: $dbname</h2>";

// Get all tables
$tables = $pdo->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);

if (empty($tables)) {
    die("No tables found in database!");
}

echo "<h3>Tables found:</h3>";
echo "<ul>";
foreach ($tables as $table) {
    echo "<li><strong>$table</strong></li>";
    
    // Show structure of each table
    $columns = $pdo->query("DESCRIBE $table")->fetchAll();
    echo "<table border='1' cellpadding='5' style='margin-left:20px; margin-bottom:20px;'>";
    echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th></tr>";
    foreach ($columns as $column) {
        echo "<tr>";
        echo "<td>" . $column['Field'] . "</td>";
        echo "<td>" . $column['Type'] . "</td>";
        echo "<td>" . $column['Null'] . "</td>";
        echo "<td>" . $column['Key'] . "</td>";
        echo "<td>" . $column['Default'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
echo "</ul>";

// Look for common user table names
$possible_user_tables = ['users', 'admins', 'accounts', 'customers', 'members', 'user', 'admin'];
foreach ($possible_user_tables as $table_name) {
    try {
        $result = $pdo->query("SELECT 1 FROM $table_name LIMIT 1");
        echo "<p style='color:green'>✓ Table '$table_name' exists</p>";
    } catch (PDOException $e) {
        // Table doesn't exist, ignore
    }
}
?>