-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
73 lines (58 loc) · 2.18 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles/css/bootstrap.min.css">
<link rel="stylesheet" href="styles/main.css">
<title>Mahasiswa</title>
</head>
<?php
require_once "connection.php";
if ($_SERVER["REQUEST_METHOD"] === "GET") {
$page = $_GET["page"];
switch ($page) {
case "":
require_once "home.php";
break;
case "edit_mhs":
$nim = $_GET["nim"];
$mhs = $db->query("SELECT * FROM mahasiswa WHERE nim = '$nim'")->fetch();
require_once "edit_mhs.php";
break;
case "delete_mhs":
require_once "delete_mhs.php";
break;
default:
require_once "404.php";
break;
}
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$method = $_POST["_method"] ?? "";
if (!$method) {
$nim = filter_input(INPUT_POST, 'nim', FILTER_SANITIZE_NUMBER_INT);
$nama = htmlspecialchars(filter_input(INPUT_POST, 'nama', FILTER_SANITIZE_STRING));
$kelas = htmlspecialchars(filter_input(INPUT_POST, 'kelas', FILTER_SANITIZE_STRING));
$prodi = htmlspecialchars(filter_input(INPUT_POST, 'prodi', FILTER_SANITIZE_STRING));
$db->query("INSERT INTO mahasiswa (nim, nama, kelas, prodi) VALUES ('$nim', '$nama', '$kelas', '$prodi')");
echo "
<script>
alert('Mahasiswa berhasil ditambahkan');
</script>
";
header("Location: /");
} else {
$nim = filter_input(INPUT_POST, 'nim', FILTER_SANITIZE_NUMBER_INT);
$nama = htmlspecialchars(filter_input(INPUT_POST, 'nama', FILTER_SANITIZE_STRING));
$kelas = htmlspecialchars(filter_input(INPUT_POST, 'kelas', FILTER_SANITIZE_STRING));
$prodi = htmlspecialchars(filter_input(INPUT_POST, 'prodi', FILTER_SANITIZE_STRING));
$db->query("UPDATE mahasiswa SET nama = '$nama', kelas = '$kelas', prodi = '$prodi' WHERE nim = '$nim'");
echo "
<script>
alert('Mahasiswa berhasil diubah');
</script>
";
header("Location: /");
}
}