<?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>Categories Table Fix</h1>";
// Check if icon_class column exists in categories table
echo "<h2>Checking Categories Table Structure</h2>";
$iconClassExists = false;
$result = $conn->query("SHOW COLUMNS FROM categories");
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'] === 'icon_class') {
$iconClassExists = true;
}
}
echo "</table>";
// Add icon_class column if it doesn't exist
if (!$iconClassExists) {
echo "<h3>Adding missing icon_class column...</h3>";
$alterResult = $conn->query("ALTER TABLE categories ADD COLUMN icon_class VARCHAR(50) DEFAULT 'fas fa-folder' AFTER description");
if ($alterResult) {
echo "<p style='color:green;'>Successfully added icon_class column to categories table.</p>";
} else {
echo "<p style='color:red;'>Failed to add icon_class column: " . $conn->error . "</p>";
}
} else {
echo "<p>icon_class column already exists.</p>";
}
} else {
echo "Error fetching categories table structure: " . $conn->error;
}
?>