-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunc.php
129 lines (93 loc) · 2.68 KB
/
func.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
//koneksi ke database
$conn = mysqli_connect("localhost", "root", "", "sisdat");
function query($query) {
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while ( $row = mysqli_fetch_assoc($result) ) {
$rows[] = $row;
}
return $rows;
}
function insert($data) {
//ambil data dari tiap elemen dri form
global $conn;
$matkul = htmlspecialchars($data["Matkul"]);
$deadline = htmlspecialchars($data["Deadline"]);
$deskripsi = htmlspecialchars($data["Deskripsi"]);
$kodekelas = htmlspecialchars($data["Kode_kelas"]);
//query insert data
$query = "INSERT INTO tugas
VALUES
('', '$matkul', '$deadline', '$deskripsi', '$kodekelas')
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function delete($kodetugas) {
global $conn;
mysqli_query($conn, "DELETE FROM tugas WHERE Kode_tugas = $kodetugas");
return mysqli_affected_rows($conn);
}
function update($data) {
global $conn;
$kodetugas = $data["Kode_tugas"];
$matkul = htmlspecialchars($data["Matkul"]);
$deadline = htmlspecialchars($data["Deadline"]);
$deskripsi = htmlspecialchars($data["Deskripsi"]);
$kodekelas = htmlspecialchars($data["Kode_kelas"]);
//query insert data
$query = "UPDATE tugas SET
Matkul = '$matkul',
Deadline = '$deadline',
Deskripsi = '$deskripsi',
Kode_kelas = '$kodekelas'
WHERE Kode_tugas = $kodetugas
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function register($data) {
global $conn;
$username = strtolower(stripslashes($data["username"]));
$password = mysqli_real_escape_string($conn, $data["password"]);
$password2 = mysqli_real_escape_string($conn, $data["password2"]);
//cek double list username
$result = mysqli_query($conn, "SELECT username FROM user WHERE username = '$username'");
if( mysqli_fetch_assoc($result) ){
echo "
<script>
alert('username already taken');
</script>
";
return false;
}
//cek konfirmasi password
if( $password != $password2 ) {
echo "
<script>
alert('password different!');
</script>
";
return false;
}
//enkripsi password
$password = password_hash($password, PASSWORD_DEFAULT);
//tambahkan user ke db
mysqli_query($conn, "INSERT INTO user VALUES('','$username','$password')");
return mysqli_affected_rows($conn);
}
function profile($data) {
global $conn;
}
function read($query){
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while($data = mysqli_fetch_assoc($result)){
$rows[] = $data;
}
return $rows;
}
?>