<?php
/**
 * Simple Error Tester for cPanel
 * Shows the exact PHP error causing the 500 error
 */

error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=utf-8');

echo "<h1>🔍 Error Test</h1>";
echo "<p>If you see an error below, that's what's causing the HTTP 500:</p>";
echo "<hr>";

try {
    // Try to include db_config.php
    echo "<h2>1. Testing db_config.php</h2>";
    require_once __DIR__ . '/db_config.php';
    
    if (isset($conn)) {
        if ($conn->connect_error) {
            echo "<p style='color: red;'><strong>❌ Database Error:</strong></p>";
            echo "<p>" . htmlspecialchars($conn->connect_error) . "</p>";
            echo "<p><strong>Attempted Connection:</strong></p>";
            echo "<ul>";
            echo "<li>Host: " . htmlspecialchars($DB_HOST) . "</li>";
            echo "<li>User: " . htmlspecialchars($DB_USER) . "</li>";
            echo "<li>Database: " . htmlspecialchars($DB_NAME) . "</li>";
            echo "</ul>";
        } else {
            echo "<p style='color: green;'><strong>✅ Database connected!</strong></p>";
            $conn->close();
        }
    } else {
        echo "<p style='color: red;'><strong>❌ \$conn variable not set</strong></p>";
    }
    
    // Try to include blog_helpers.php
    echo "<h2>2. Testing blog_helpers.php</h2>";
    if (file_exists(__DIR__ . '/blog_helpers.php')) {
        require_once __DIR__ . '/blog_helpers.php';
        echo "<p style='color: green;'><strong>✅ blog_helpers.php loaded</strong></p>";
    } else {
        echo "<p style='color: red;'><strong>❌ blog_helpers.php not found</strong></p>";
    }
    
    echo "<h2>3. Environment Info</h2>";
    echo "<ul>";
    echo "<li>Domain: " . htmlspecialchars($_SERVER['HTTP_HOST']) . "</li>";
    echo "<li>PHP: " . phpversion() . "</li>";
    echo "<li>MySQLi: " . (extension_loaded('mysqli') ? "✅ Loaded" : "❌ Not loaded") . "</li>";
    echo "</ul>";
    
} catch (Exception $e) {
    echo "<p style='color: red;'><strong>❌ Exception:</strong></p>";
    echo "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>";
    echo "<pre>" . htmlspecialchars($e->getTraceAsString()) . "</pre>";
} catch (Error $e) {
    echo "<p style='color: red;'><strong>❌ Fatal Error:</strong></p>";
    echo "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>";
    echo "<pre>" . htmlspecialchars($e->getTraceAsString()) . "</pre>";
}

echo "<hr>";
echo "<p><strong>📝 Note:</strong> If you see any red errors above, that's what you need to fix.</p>";
echo "<p><a href='cpanel_diagnostic.php'>Go to Full Diagnostic</a></p>";
?>
