<?php
$question_id = $_GET['q_index'] ?? 0;
$matric = $_SESSION['matric'] ?? null;

$stmt = $pdo->prepare("SELECT chosen_option FROM answers_record WHERE matric = ? AND question_id = ?");
$stmt->execute([$matric, $question_id]);
$saved_answer = $stmt->fetchColumn();
?>

<input type="hidden" name="selected_answer" value="<?php echo $saved_answer; ?>">
