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

// Include database config
require_once 'config.php';

echo "=== Database Table Structure ===\n\n";

// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error() . "\n";
    exit();
}

// Get list of tables
$tables_result = mysqli_query($condb, "SHOW TABLES");
echo "Tables in database:\n";
while ($table_row = mysqli_fetch_row($tables_result)) {
    $table_name = $table_row[0];
    echo "- $table_name\n";
    
    // Get table structure
    $structure_result = mysqli_query($condb, "DESCRIBE $table_name");
    if ($structure_result) {
        echo "  Columns:\n";
        while ($column_row = mysqli_fetch_assoc($structure_result)) {
            $field = $column_row['Field'];
            $type = $column_row['Type'];
            $null = $column_row['Null'] === 'YES' ? 'NULL' : 'NOT NULL';
            $key = empty($column_row['Key']) ? '' : $column_row['Key'];
            $default = $column_row['Default'] === NULL ? 'NULL' : $column_row['Default'];
            
            echo "  - $field ($type) $null" . 
                 ($key ? " KEY:$key" : "") . 
                 ($default ? " DEFAULT:$default" : "") . "\n";
        }
    } else {
        echo "  Error getting table structure: " . mysqli_error($condb) . "\n";
    }
    echo "\n";
}

// Test insertion into bot table
echo "Testing insertion into bot table...\n";
$hwid = 'TEST' . time();

// Test direct insertion
$query = "INSERT INTO bot (hwid, Date_Time, IP, Country) VALUES ('$hwid', NOW(), '127.0.0.1', 'US')";
if (mysqli_query($condb, $query)) {
    echo "Inserted record with HWID: $hwid\n";
} else {
    echo "Error inserting record: " . mysqli_error($condb) . "\n";
    
    // Try with lowercase column name
    $query = "INSERT INTO bot (hwid, Date_Time, IP, Country) VALUES ('$hwid', NOW(), '127.0.0.1', 'US')";
    if (mysqli_query($condb, $query)) {
        echo "Inserted record with lowercase hwid: $hwid\n";
    } else {
        echo "Error inserting with lowercase hwid: " . mysqli_error($condb) . "\n";
    }
}

echo "\nDone.\n";
?> 