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

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

echo "<h2>Updating Users Table</h2>";

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>✅ Added profile_image column to users table.</p>";
        } else {
            throw new Exception("Failed to add profile_image column: " . $conn->error);
        }
    } else {
        echo "<p>ℹ️ 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>✅ Added designation column to users table.</p>";
        } else {
            throw new Exception("Failed to add designation column: " . $conn->error);
        }
    } else {
        echo "<p>ℹ️ 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>✅ Added expertise column to users table.</p>";
        } else {
            throw new Exception("Failed to add expertise column: " . $conn->error);
        }
    } else {
        echo "<p>ℹ️ 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>✅ Added bio column to users table.</p>";
        } else {
            throw new Exception("Failed to add bio column: " . $conn->error);
        }
    } else {
        echo "<p>ℹ️ 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>✅ Added social_links column to users table.</p>";
        } else {
            throw new Exception("Failed to add social_links column: " . $conn->error);
        }
    } else {
        echo "<p>ℹ️ social_links column already exists.</p>";
    }

    echo "<p>✅ 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 style='color: red;'>❌ Error: " . $e->getMessage() . "</p>";
    echo "<p>Return to <a href='../../admin/index.php'>Admin Dashboard</a> or <a href='../../index.php'>Homepage</a></p>";
}
?>