<?php
session_start();
require_once "../includes/db.php";

if (!isset($_SESSION['admin'])) {
    header("Location: index.php");
    exit;
}

$student_id = intval($_POST['student_id']);
$exam_id = intval($_POST['exam_id']);

// Delete the student's result for this exam so they can retake
$stmt = $conn->prepare("DELETE FROM results WHERE student_id=? AND id=?");
$stmt->bind_param("ii", $student_id, $exam_id);
$stmt->execute();

header("Location: view_results.php?reset=success");
exit;
?>
