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

<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "popularcomputer";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Check if the exam_schedules table exists
$tableCheck = $conn->query("SHOW TABLES LIKE 'exam_schedules'");
if ($tableCheck->num_rows == 0) {
    echo "The exam_schedules table does not exist. Creating it...<br>";
    
    // Create the table
    $createTable = "
    CREATE TABLE `exam_schedules` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `course_id` int(11) NOT NULL,
        `title` varchar(255) NOT NULL,
        `description` text,
        `exam_date` date NOT NULL,
        `start_time` time NOT NULL,
        `end_time` time NOT NULL,
        `duration` int(11) NOT NULL COMMENT 'in minutes',
        `passing_percentage` float NOT NULL DEFAULT '50',
        `attempts_allowed` int(11) NOT NULL DEFAULT '1',
        `allow_late_attempts` tinyint(1) NOT NULL DEFAULT '0',
        `is_active` tinyint(1) NOT NULL DEFAULT '1',
        `total_marks` int(11) NOT NULL DEFAULT '100',
        `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (`id`),
        KEY `course_id` (`course_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    ";
    
    if ($conn->query($createTable) === TRUE) {
        echo "Table exam_schedules created successfully<br>";
    } else {
        echo "Error creating table: " . $conn->error . "<br>";
    }
} else {
    echo "The exam_schedules table exists. Checking its structure...<br>";
    
    // Get the table columns
    $columnsQuery = $conn->query("SHOW COLUMNS FROM exam_schedules");
    echo "<h3>Current exam_schedules table structure:</h3>";
    echo "<table border='1'><tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
    
    $hasActiveColumn = false;
    $hasStatusColumn = false;
    
    while($column = $columnsQuery->fetch_assoc()) {
        echo "<tr>";
        echo "<td>" . $column['Field'] . "</td>";
        echo "<td>" . $column['Type'] . "</td>";
        echo "<td>" . $column['Null'] . "</td>";
        echo "<td>" . $column['Key'] . "</td>";
        echo "<td>" . $column['Default'] . "</td>";
        echo "<td>" . $column['Extra'] . "</td>";
        echo "</tr>";
        
        if ($column['Field'] == 'is_active') {
            $hasActiveColumn = true;
        }
        if ($column['Field'] == 'status') {
            $hasStatusColumn = true;
        }
    }
    echo "</table><br>";
    
    // Check if we need to add columns
    if (!$hasActiveColumn) {
        $addActiveColumn = "ALTER TABLE exam_schedules ADD COLUMN is_active TINYINT(1) NOT NULL DEFAULT 1 AFTER allow_late_attempts";
        if ($conn->query($addActiveColumn) === TRUE) {
            echo "Added is_active column to the table<br>";
        } else {
            echo "Error adding is_active column: " . $conn->error . "<br>";
        }
    }
}

// Close connection
$conn->close();

// Add navigation button
echo "<p><a href='student/scheduled-exams.php'>Go to Scheduled Exams</a></p>";
?>