<?php
session_start();
if (!isset($_SESSION['id_pelajar'])) {
    header('Location: login_pelajar.php');
    exit;
}

include 'includes/config.php';

$id_pelajar = (int) $_SESSION['id_pelajar'];
$id_aktiviti = isset($_GET['id']) ? (int) $_GET['id'] : 0;

if ($id_aktiviti > 0) {
    $sql = "DELETE FROM penyertaan WHERE pelajar_id = $id_pelajar AND aktiviti_id = $id_aktiviti";
    mysqli_query($conn, $sql);
}

header('Location: senarai_aktiviti_pelajar.php?msg=' . urlencode('Anda telah membatalkan penglibatan aktiviti ini.'));
exit;
