<?php
// Include database configuration
require_once 'admin/database/db_config.php';
// Display header
echo "<!DOCTYPE html>
<html>
<head>
<title>Updating Users Table</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; }
h1 { color: #333; }
.success { color: green; }
.error { color: red; }
.info { color: blue; }
</style>
</head>
<body>
<h1>Updating Users Table</h1>";
try {
// Check if the users table exists
$table_exists = $conn->query("SHOW TABLES LIKE 'users'");
if ($table_exists->num_rows == 0) {
throw new Exception("Users table does not exist!");
}
// Add profile_image column if it doesn't exist
$column_exists = $conn->query("SHOW COLUMNS FROM users LIKE 'profile_image'");
if ($column_exists->num_rows == 0) {
if ($conn->query("ALTER TABLE users ADD COLUMN profile_image VARCHAR(255) DEFAULT NULL")) {
echo "<p class='success'>✅ Added profile_image column to users table.</p>";
} else {
throw new Exception("Failed to add profile_image column: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ profile_image column already exists.</p>";
}
// Add designation column if it doesn't exist
$column_exists = $conn->query("SHOW COLUMNS FROM users LIKE 'designation'");
if ($column_exists->num_rows == 0) {
if ($conn->query("ALTER TABLE users ADD COLUMN designation VARCHAR(255) DEFAULT NULL")) {
echo "<p class='success'>✅ Added designation column to users table.</p>";
} else {
throw new Exception("Failed to add designation column: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ designation column already exists.</p>";
}
// Add expertise column if it doesn't exist
$column_exists = $conn->query("SHOW COLUMNS FROM users LIKE 'expertise'");
if ($column_exists->num_rows == 0) {
if ($conn->query("ALTER TABLE users ADD COLUMN expertise VARCHAR(255) DEFAULT NULL")) {
echo "<p class='success'>✅ Added expertise column to users table.</p>";
} else {
throw new Exception("Failed to add expertise column: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ expertise column already exists.</p>";
}
// Add bio column if it doesn't exist
$column_exists = $conn->query("SHOW COLUMNS FROM users LIKE 'bio'");
if ($column_exists->num_rows == 0) {
if ($conn->query("ALTER TABLE users ADD COLUMN bio TEXT DEFAULT NULL")) {
echo "<p class='success'>✅ Added bio column to users table.</p>";
} else {
throw new Exception("Failed to add bio column: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ bio column already exists.</p>";
}
// Add social_links column if it doesn't exist
$column_exists = $conn->query("SHOW COLUMNS FROM users LIKE 'social_links'");
if ($column_exists->num_rows == 0) {
if ($conn->query("ALTER TABLE users ADD COLUMN social_links TEXT DEFAULT NULL")) {
echo "<p class='success'>✅ Added social_links column to users table.</p>";
} else {
throw new Exception("Failed to add social_links column: " . $conn->error);
}
} else {
echo "<p class='info'>ℹ️ social_links column already exists.</p>";
}
echo "<p class='success'>✅ Users table structure has been updated successfully.</p>";
echo "<p>Return to <a href='admin/instructors.php'>Instructors Management</a> or <a href='index.php'>Homepage</a></p>";
} catch (Exception $e) {
echo "<p class='error'>❌ Error: " . $e->getMessage() . "</p>";
echo "<p>Return to <a href='admin/index.php'>Admin Dashboard</a> or <a href='index.php'>Homepage</a></p>";
}
echo "</body></html>";
?>