0) { try { $pdo = getPdoConnection(true); ensureLab04StudentsTable($pdo, false); // Lấy tên sinh viên trước khi xóa để thông báo rõ ràng $findStmt = $pdo->prepare("SELECT name FROM students WHERE id = :id"); $findStmt->execute([':id' => $id]); $student = $findStmt->fetch(); if ($student) { $delStmt = $pdo->prepare("DELETE FROM students WHERE id = :id"); $delStmt->execute([':id' => $id]); header('Location: index.php?msg=' . urlencode("Đã xóa sinh viên \"{$student['name']}\" (ID #{$id}) thành công!")); exit; } else { header('Location: index.php?err=' . urlencode("Không tìm thấy sinh viên có ID #{$id}.")); exit; } } catch (Throwable $e) { header('Location: index.php?err=' . urlencode('Lỗi khi xóa: ' . $e->getMessage())); exit; } } // Nếu truy cập delete_student.php không kèm id, hiển thị giao diện index.php require_once __DIR__ . '/index.php';