-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubah.php
112 lines (97 loc) · 2.77 KB
/
ubah.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
// koneksi ke DBMS
require "./functions.php";
// ambil data di url
$id = $_GET["id"];
// query data mahasiswa berdasarkan id
$students = get_data("SELECT *, students.id FROM ((students
INNER JOIN role ON students.role = role.id)
INNER JOIN position ON students.position = position.id)
WHERE students.id = $id")[0];
// mengambil data role dan position
$roles = get_data("SELECT * FROM role");
$positions = get_data("SELECT * FROM position");
if (isset($_POST["submit"])) {
// cek apakah data berhasil di ubah atau tidak
if (edit_data($_POST) > 0) {
echo "
<script>
alert('Success to editing data!');
document.location.href = './index.php';
</script>
";
} else {
echo "
<script>
alert('Failed to editing data!');
document.location.href = './index.php';
</script>
";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit student data</title>
<style>
ul>li {
height: 50px;
}
</style>
</head>
<body>
<a href="./index.php">Back</a>
<h1>Edit student data</h1>
<form action="" method="post">
<input type="hidden" name="id" value="<?= $students["id"]; ?>">
<ul>
<li>
<label for="name">
Name :
<input type="text" name="name" id="name" value="<?= $students["name"]; ?>" required>
</label>
</li>
<li>
<label for="school">
School :
<input type="text" name="school" id="school" value="<?= $students["school"]; ?>" required>
</label>
</li>
<li>
<label for="role">
Role :
<select name="role" id="role" required>
<option value="">None :</option>
<?php foreach ($roles as $role) : ?>
<option value="<?= $role["id"] ?>" <?= ($students["role"] == $role["id"]) ? "selected" : false ?>><?= $role["name_role"]; ?></option>
<?php endforeach; ?>
</select>
</label>
</li>
<li>
<label for="position">
Position :
<select name="position" id="position" required>
<option value="">None :</option>
<?php foreach ($positions as $position) : ?>
<option value="<?= $position["id"]; ?>" <?= ($students["position"] == $position["id"]) ? "selected" : false ?>><?= $position["name_position"]; ?></option>
<?php endforeach; ?>
</select>
</label>
</li>
<li>
<label for="image">
Image :
<input type="file" name="image" id="image">
</label>
</li>
<li>
<button type="submit" name="submit">Edit Data!</button>
</li>
</ul>
</form>
</body>
</html>