<?php
include 'includes/db.php';

echo "<h2>Database Diagnosis</h2>";

// Check if blogs table exists
$result = $conn->query("SHOW TABLES LIKE 'blogs'");
if ($result->num_rows > 0) {
    echo "<p style='color:green'>Table 'blogs' exists.</p>";
} else {
    echo "<p style='color:red'>Table 'blogs' DOES NOT exist.</p>";
    // Attempt to create it again
    $sql = "CREATE TABLE IF NOT EXISTS blogs (
        id INT(11) NOT NULL AUTO_INCREMENT,
        title VARCHAR(255) NOT NULL,
        content TEXT NOT NULL,
        image_url VARCHAR(255) DEFAULT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (id)
    )";
    if ($conn->query($sql) === TRUE) {
        echo "<p style='color:green'>Table 'blogs' created successfully.</p>";
    } else {
        echo "<p style='color:red'>Error creating table 'blogs': " . $conn->error . "</p>";
    }
}

// Check services table columns
echo "<h3>Services Table Columns:</h3>";
$result = $conn->query("SHOW COLUMNS FROM services");
if ($result) {
    echo "<ul>";
    while ($row = $result->fetch_assoc()) {
        echo "<li>" . $row['Field'] . " (" . $row['Type'] . ")</li>";
    }
    echo "</ul>";
} else {
    echo "<p style='color:red'>Error checking services table: " . $conn->error . "</p>";
}
?>
