-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
64 lines (53 loc) · 1.81 KB
/
register.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
<?php
require_once "core/init.php";
$error = '';
if (isset($_SESSION['user'])) {
header('Location: index.php');
}
if (isset($_POST['submit'])) {
$nama = $_POST['nama'];
$username = $_POST['username'];
$password = $_POST['password'];
if (!empty(trim($nama)) && !empty(trim($username)) && !empty(trim($password))) {
if (register_cek_username($username)) {
if (register_user($nama, $username, $password)) {
header("Location: login.php");
} else{
$error = "gagal melalukan registrasi";
}
} else{
$error = "username sudah terdaftar";
}
} else{
$error = "data tidak boleh kosong";
}
}
require_once "view/header.php";
?>
<div class="container mt-5">
<h1 class="text-center">Register</h1>
<p class="text-center">jika punya akun sini <a href="login.php">login</a></p>
<form action="" method="POST">
<div class="mb-3">
<label for="nama" class="form-label">Nama</label>
<input type="text" name="nama" class="form-control" id="nama" autocomplete="off">
</div>
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" name="username" class="form-control" id="username" autocomplete="off">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" name="password" class="form-control" id="password">
</div>
<?php if ($error != '') { ?>
<div class="alert alert-danger" role="alert">
<?= $error ?>
</div>
<?php } ?>
<button type="submit" name="submit" class="btn btn-primary">Register</button>
</form>
</div>
<?php
require_once "view/header.php";
?>