-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
76 lines (66 loc) · 2.19 KB
/
edit.php
File metadata and controls
76 lines (66 loc) · 2.19 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
session_start();
// Check if ID is provided
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 student data
$studentData = null;
foreach ($mahasiswa as $mhs) {
if ($mhs['nim'] === $nim) {
$studentData = $mhs;
break;
}
}
// If student not found, redirect
if (!$studentData) {
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Data Mahasiswa</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<nav>
<a href="index.php">Daftar Mahasiswa</a> |
<a href="tambah.php">Tambah Mahasiswa</a>
</nav>
<h2>Edit Data Mahasiswa</h2>
<div class="form-container">
<form method="POST" action="update.php">
<input type="hidden" name="old_nim" value="<?= htmlspecialchars($studentData['nim']) ?>">
<div class="form-group">
<label>Nama:</label>
<input type="text" name="nama" required value="<?= htmlspecialchars($studentData['nama']) ?>">
</div>
<div class="form-group">
<label>NIM:</label>
<input type="text" name="nim" required value="<?= htmlspecialchars($studentData['nim']) ?>">
</div>
<div class="nilai-section">
<h3>Nilai Mata Kuliah</h3>
<?php foreach ($studentData['mk'] as $index => $matkul): ?>
<div class="form-group">
<label><?= htmlspecialchars($matkul['nama']) ?>:</label>
<input type="number" name="nilai[]" required min="0" max="100"
value="<?= htmlspecialchars($matkul['nilai']) ?>" placeholder="0-100">
</div>
<?php endforeach; ?>
</div>
<div class="button-group">
<button type="submit" class="submit-btn">Simpan Perubahan</button>
<a href="index.php" class="cancel-btn">Batal</a>
</div>
</form>
</div>
</body>
</html>