-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
49 lines (40 loc) · 1.3 KB
/
functions.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
<?php
//koneksi ke database
$conn = mysqli_connect("localhost", "root", "", "dbpkendaraan");
function query($query) {
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while ( $row = mysqli_fetch_assoc($result) ){
$rows[] = $row;
}
return $rows;
}
function registrasi($data){
global $conn;
$username = strtolower(stripslashes($data['username']));
$email = strtolower(stripslashes($data['email']));
$password = mysqli_real_escape_string($conn, $data['password']);
$password2 = mysqli_real_escape_string($conn,$data['password2']);
//cek username sudah ada atau belum
$result = mysqli_query($conn, "SELECT username FROM user WHERE username= '$username'");
if (mysqli_fetch_assoc($result) ){
echo "<script>
alert('username sudah ada!');
</script>";
return false;
}
//cek konfirmasi password
if( $password !== $password2){
echo "<script>
alert('konfirmasi password tidak sesuai!');
</script>";
return false;
}
// enkripsi password
$password = password_hash($password, PASSWORD_DEFAULT);
// tambahkan user baru ke database
mysqli_query($conn, "INSERT INTO user VALUES('', '$username', '$email','$password')");
return mysqli_affected_rows($conn);
}
?>