<?php
require_once 'config/database.php';

// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "<h1>Verifying class_teachers Table Fix</h1>";

try {
    // Check if class_teachers table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'class_teachers'");
    $table_exists = $stmt->fetch();
    
    if ($table_exists) {
        echo "<p style='color: green; font-size: 18px;'>✅ SUCCESS: class_teachers table exists!</p>";
        
        // Show table structure
        echo "<h2>Table Structure:</h2>";
        $stmt = $pdo->query("DESCRIBE class_teachers");
        $columns = $stmt->fetchAll();
        echo "<table border='1' style='border-collapse: collapse;'>";
        echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</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 "<td>{$column['Extra']}</td>";
            echo "</tr>";
        }
        echo "</table>";
        
        // Count existing records
        $stmt = $pdo->query("SELECT COUNT(*) as count FROM class_teachers");
        $count = $stmt->fetch();
        echo "<h3>Current records in class_teachers: {$count['count']}</h3>";
        
        echo "<p style='color: green; font-size: 16px;'>🎉 The 500 error on my_students.php should now be fixed!</p>";
        echo "<p><a href='teachers/my_students.php' style='font-size: 16px;'>Go to My Students Page</a></p>";
    } else {
        echo "<p style='color: red; font-size: 18px;'>❌ ERROR: class_teachers table does not exist!</p>";
    }
} catch (Exception $e) {
    echo "<p style='color: red;'>ERROR: " . $e->getMessage() . "</p>";
}
?>