-
Notifications
You must be signed in to change notification settings - Fork 0
/
prosesRegistrasi.php
68 lines (61 loc) · 2.4 KB
/
prosesRegistrasi.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
<?php
include "administrator/database.php";
$db = new database();
$aksi = $_GET['aksi'];
if ($aksi == "profil") {
$namaFile = $_FILES['foto']['name'];
$error = $_FILES['foto']['error'];
$tmpName = $_FILES['foto']['tmp_name'];
// cek apakah tidak ada gambar yang di upload
if ($error === 4) {
echo " <script>
alert('pilih gambar terlebih dahulu!');
document.location = 'buatProfil.php';
</script>";
return false;
}
// cek apakah yang di upload adalah gambar
$ekstensiGambarValid = ['jpg', 'jpeg', 'png'];
$ekstensiGambar = explode('.', $namaFile);
$ekstensiGambar = strtolower(end($ekstensiGambar));
if (!in_array($ekstensiGambar, $ekstensiGambarValid)) {
echo " <script>
alert('yang anda upload bukan gambar!');
document.location = 'buatProfil.php';
</script>";
return false;
}
// lolos pengecekan, gambar siap di upload
// generate nama gambar baru
$foto_baru = uniqid();
$foto_baru .= '.';
$foto_baru .= $ekstensiGambar;
move_uploaded_file($tmpName, 'img/profil/' . $foto_baru);
$query = mysqli_query($db->koneksi, "SELECT * FROM login ORDER BY id_login DESC LIMIT 1");
$row = mysqli_fetch_array($query);
$id_login = $row['id_login'];
$db->inputProfil($id_login, $_POST['nama'], $_POST['nik'], $_POST['email'], $_POST['noHp'], $_POST['tempat_lahir'], $_POST['tgl_lahir'], $_POST['umur'], $_POST['jns_kelamin'], $_POST['status'], $_POST['alamat'], $foto_baru);
echo "
<script language = 'Javascript'>
alert('Data Berhasil Ditambahkan, silahkan melakukan login!');
document.location = 'index.php';
</script>";
} elseif ($aksi == "registrasi") {
$username = $_POST['username'];
$password = $_POST['password'];
$level = 'User';
$q = mysqli_query($db->koneksi, "SELECT * FROM login WHERE username = '$username'");
$cek = mysqli_num_rows($q);
if ($cek > 0) {
echo "<script language = 'JavaScript'>
document.location='registrasi.php?pesan=gagal';</script>";
} else {
$db->inputLogin($username, $password, $level);
echo "<script language = 'JavaScript'>
alert('Anda telah berhasil membuat Akun, Silahkan memasukkan data diri!');
document.location='buatProfil.php';
</script>";
}
} else {
echo "Database Error, Silahkan Proses Kembali <a href='registrasi.php'>Klik Disini</a>";
}