50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
session_start();
|
|
require_once "Config.php";
|
|
|
|
if(isset($_POST['btn-register'])) {
|
|
$username = $_POST['username'];
|
|
$email = $_POST['email'];
|
|
$password = $_POST['password'];
|
|
$confirmPassword = password_hash($_POST['confirm_password'],PASSWORD_DEFAULT);
|
|
|
|
if (!$username || !$email || !$password || !$confirmPassword) {
|
|
echo "<script>alert('Semua field harus diisi'); window.history.back();</script>";
|
|
exit;
|
|
}
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
echo "<script>alert('Format email tidak valid'); window.history.back();</script>";
|
|
exit;
|
|
}
|
|
|
|
if ($password !== $confirmPassword) {
|
|
echo "<script>alert('Password dan konfirmasi password tidak cocok'); window.history.back();</script>";
|
|
exit;
|
|
}
|
|
|
|
if (strlen($password) < 6) {
|
|
echo "<script>alert('Password minimal 6 karakter'); window.history.back();</script>";
|
|
exit;
|
|
}
|
|
|
|
|
|
$stmt = mysqli_prepare($conn, "SELECT id FROM user WHERE username=? OR email=?");
|
|
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
|
|
mysqli_stmt_execute($stmt);
|
|
mysqli_stmt_store_result($stmt);
|
|
|
|
if (mysqli_stmt_num_rows($stmt) > 0) {
|
|
echo "<script>alert('Username atau email sudah digunakan'); window.history.back();</script>";
|
|
exit;
|
|
}
|
|
|
|
$stmt = mysqli_prepare($conn, "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, 'player')");
|
|
mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hash);
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
echo "<script>alert('Registrasi berhasil! Silakan login.'); window.location.href='login.html';</script>";
|
|
exit;
|
|
}
|
|
?>
|