<?php
session_start();
if (!isset($_SESSION['id_admin'])) {
    header('Location: login_admin.php');
    exit;
}
include 'includes/config.php';

if (!isset($_GET['id'])) {
    header('Location: senarai_pelajar.php');
    exit;
}

$id = intval($_GET['id']);

// Dapatkan gambar pelajar untuk padam file sekali
$result = $conn->query("SELECT gambar FROM pelajar WHERE id = $id");
$row = $result->fetch_assoc();

if ($row && !empty($row['gambar']) && file_exists("uploads/pelajar/" . $row['gambar'])) {
    unlink("uploads/pelajar/" . $row['gambar']);
}

$conn->query("DELETE FROM pelajar WHERE id = $id");

header('Location: senarai_pelajar.php');
exit;
?>
