<?php
// Include your PDO database connection file
include('db.php');

// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Get the topic ID and new status
    $topic_id = $_POST['topic_id'];
    $new_status = $_POST['status'];

    // Prepare the SQL update query using PDO
    $query = "UPDATE topics SET status = :status WHERE id = :id";
    
    // Prepare the statement
    $stmt = $pdo->prepare($query);

    // Bind the parameters
    $stmt->bindParam(':status', $new_status, PDO::PARAM_INT);
    $stmt->bindParam(':id', $topic_id, PDO::PARAM_INT);

    // Execute the query and check if the update was successful
    if ($stmt->execute()) {
        // Redirect back to the topics page with success message
        header("Location: quiz_management.php?status=updated");
        exit();
    } else {
        // Handle errors
        echo "Failed to update status.";
    }
}
