alert('Semua field harus diisi'); window.history.back();";
exit;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "";
exit;
}
if ($password !== $confirmPassword) {
echo "";
exit;
}
if (strlen($password) < 6) {
echo "";
exit;
}
// cek username & email di database
$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 "";
exit;
}
// hash password
$hash = password_hash($password, PASSWORD_DEFAULT);
// insert user
$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 "";
exit;
}
?>