<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }

        form {
            background-color: #ffffff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            max-width: 600px;
            margin: auto;
        }

        label {
            display: block;
            margin: 10px 0 5px;
        }

        input[type="text"], input[type="number"], input[type="file"], input[type="submit"], select {
            width: 100%;
            padding: 10px;
            margin: 5px 0 15px;
            border: 1px solid #cccccc;
            border-radius: 4px;
        }

        input[type="submit"] {
            background-color: #007BFF;
            color: white;
            border: none;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>

<?php
// Database connection details
$host = 'localhost';
$dbname = 'cbt'; // Replace with your actual database name
$username = 'root'; // Replace with your database username
$password = ''; // Replace with your database password

try {
    // Create a new PDO instance
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Check if the form is submitted
    if (isset($_POST['update_status'])) {
        $selectedLevel = $_POST['level'];

        // Update the status of students with the selected level
        $updateQuery = "UPDATE students SET duration = :status WHERE level = :level";
        $stmt = $pdo->prepare($updateQuery);
        $stmt->execute([
            ':status' => $_POST['dtime'],
            ':level' => $selectedLevel
        ]);

        // Confirm update
        echo "Timer Set For sttudents In: " . htmlspecialchars($selectedLevel);
    }

    // Fetch levels for dropdown (you can modify this query based on your levels)
    $levelsQuery = "SELECT DISTINCT level FROM students";
    $levelsStmt = $pdo->query($levelsQuery);

    
} catch (PDOException $e) {
    // Handle any errors
    echo "Error: " . $e->getMessage();
}
?>

<!-- HTML Form for selecting level -->
<form action="" method="post">
	<input type="number" name="dtime" value="" placeholder="Enter Duration in minutes"  required />
    <label for="level">Select Level:</label>
    <select name="level" id="level" required>
        <option value="">--Select Level--</option>
       	<option>NDI</option>
		<option>NDII</option>
		<option>HNDI</option>
		<option>HNDII</option>
		<!--<option>500LEVEL</option>-->
    </select>
    <input type="submit" name="update_status" value="SET EXAMINATION TIME">
</form>
