Sindbad~EG File Manager
<?php
require_once 'config/database.php';
try {
$database = new Database();
$conn = $database->getConnection();
echo "<h2>Checking and Fixing News Table Location Field</h2>";
// Check current structure
$stmt = $conn->query("SHOW COLUMNS FROM news");
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
$hasLocationColumn = false;
$hasLocationIdColumn = false;
foreach ($columns as $column) {
if ($column['Field'] === 'location') {
$hasLocationColumn = true;
echo "<p>Found legacy 'location' column: " . $column['Type'] . " (Null: " . $column['Null'] . ")</p>";
}
if ($column['Field'] === 'location_id') {
$hasLocationIdColumn = true;
echo "<p>Found 'location_id' column: " . $column['Type'] . " (Null: " . $column['Null'] . ")</p>";
}
}
// If legacy location column exists and is NOT NULL, we need to fix it
if ($hasLocationColumn) {
echo "<p><strong>Fixing legacy location column...</strong></p>";
// First, make the column nullable or drop it
$conn->exec("ALTER TABLE news DROP COLUMN location");
echo "<p>✓ Dropped legacy 'location' column</p>";
}
if (!$hasLocationIdColumn) {
echo "<p><strong>Adding location_id column...</strong></p>";
$conn->exec("ALTER TABLE news ADD COLUMN location_id INT NOT NULL AFTER title");
echo "<p>✓ Added location_id column</p>";
}
echo "<p><strong>News table structure fixed!</strong></p>";
} catch (Exception $e) {
echo "<p style='color: red;'>Error: " . $e->getMessage() . "</p>";
}
?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists