-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
61 lines (47 loc) · 1.44 KB
/
function.php
File metadata and controls
61 lines (47 loc) · 1.44 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
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "phpdasar";
$conn = mysqli_connect($host, $user, $pass, $db);
// Fungsi Query Handling
function query($query) {
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
// Fungsi menambahkan data mahasiswa (add.php)
function addData($data) {
global $conn;
$NRP = htmlspecialchars($data["NRP"]);
$Nama = htmlspecialchars($data["Nama"]);
$Email = htmlspecialchars($data["Email"]);
$Jurusan = htmlspecialchars($data["Jurusan"]);
$query = "INSERT INTO mahasiswa VALUES ('', '$NRP', '$Nama', '$Email', '$Jurusan')";
mysqli_query($conn, $query);
}
//Fungsi menghapus data mahasiswa (delete.php)
function deleteData($id) {
global $conn;
mysqli_query($conn, "DELETE FROM mahasiswa WHERE id = $id");
return mysqli_affected_rows($conn);
}
//Fungsi mengeubah data mahasiswa (edit.php)
function editData($data) {
global $conn;
$id = $data['ID'];
$NRP = htmlspecialchars($data["NRP"]);
$Nama = htmlspecialchars($data["Nama"]);
$Email = htmlspecialchars($data["Email"]);
$Jurusan = htmlspecialchars($data["Jurusan"]);
$query = "UPDATE mahasiswa SET
NRP = '$NRP', Nama = '$Nama', Email = '$Email', Jurusan = '$Jurusan'
WHERE ID = '$id' ";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
?>