Path : /home/vishqocm/pcib.in/admin/
File Upload :
Current File : /home/vishqocm//pcib.in/admin/debug_courses.php

<?php
// Include database configuration
require_once '../admin/database/db_config.php';

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

echo "<h1>Courses Table Fix</h1>";

// Check if duration column exists in courses table
echo "<h2>Checking Courses Table Structure</h2>";
$durationExists = false;
$result = $conn->query("SHOW COLUMNS FROM courses");
if ($result) {
    echo "<table border='1'><tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
    while ($row = $result->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $row['Field'] . "</td>";
        echo "<td>" . $row['Type'] . "</td>";
        echo "<td>" . $row['Null'] . "</td>";
        echo "<td>" . $row['Key'] . "</td>";
        echo "<td>" . ($row['Default'] !== NULL ? $row['Default'] : "NULL") . "</td>";
        echo "<td>" . $row['Extra'] . "</td>";
        echo "</tr>";
        
        if ($row['Field'] === 'duration') {
            $durationExists = true;
        }
    }
    echo "</table>";
    
    // Add duration column if it doesn't exist
    if (!$durationExists) {
        echo "<h3>Adding missing duration column...</h3>";
        $alterResult = $conn->query("ALTER TABLE courses ADD COLUMN duration VARCHAR(50) DEFAULT NULL AFTER price");
        if ($alterResult) {
            echo "<p style='color:green;'>Successfully added duration column to courses table.</p>";
        } else {
            echo "<p style='color:red;'>Failed to add duration column: " . $conn->error . "</p>";
        }
    } else {
        echo "<p>Duration column already exists.</p>";
    }
} else {
    echo "Error fetching courses table structure: " . $conn->error;
}
?>