Professional Documents
Culture Documents
Registrasi
Registrasi
php
<?php
require 'function.php';
if (isset($_POST['register'])) {
if (registrasi($_POST) > 0) {
echo "<script>
alert('user baru berhasil ditambahkan');
document.location.href='login.php';
</script>
";
}else{
echo mysqli_error($connect);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Halaman Registrasi</title>
</head>
<body>
<h1> Halaman Registrasi </h1>
<form action="" method="post">
<ul>
<li>
<label for="username">Username</label>
<input type="text" name="username" id="username">
</li>
<li>
<label for="password">Password1</label>
<input type="password" name="password" id="password">
</li>
<li>
<label for="password2">Password2</label>
<input type="password" name="password2" id="password2">
</li>
<li>
<button type="submit" name="register">Registrasi</button>
</li>
</ul>
</form>
</body>
</html>
1|registrasi
Function.php
function registrasi($data){
global $connect;
$username = strtolower(stripslashes($data["username"]));
$password = mysqli_real_escape_string($connect, $data["password"]);
$password2 = mysqli_real_escape_string($connect, $data["password2"]);
if (mysqli_fetch_assoc($result)){
echo "<script>
alert('username sudah terdaftar')
</script>";
return false;
}
//enkripsi password
$password = password_hash($password, PASSWORD_DEFAULT);
// var_dump($password); die();
return mysqli_affected_rows($connect);
}
?>
2|registrasi