-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.php
More file actions
33 lines (28 loc) · 713 Bytes
/
Copy pathdelete.php
File metadata and controls
33 lines (28 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
session_start();
if (!isset($_GET['nim'])) {
header("Location: index.php");
exit();
}
$nim = $_GET['nim'];
// Read JSON file
$jsonFile = "data_mahasiswa.json";
$mahasiswa = json_decode(file_get_contents($jsonFile), true);
// Find and remove student
$found = false;
foreach ($mahasiswa as $key => $mhs) {
if ($mhs['nim'] === $nim) {
unset($mahasiswa[$key]);
$found = true;
break;
}
}
if ($found) {
// Reindex array and save
$mahasiswa = array_values($mahasiswa);
file_put_contents($jsonFile, json_encode($mahasiswa, JSON_PRETTY_PRINT));
header("Location: index.php?status=deleted");
} else {
die("Error: Data mahasiswa tidak ditemukan!");
}
?>