Postingan lainnya
PASSWORD MASUK KE USERNAME
sebelumnya saya sudah mengikuti cara membuat login dan register form, tetapi , saat saya coba register, saya masukan username email dan password, hasilnya berhasil, tapi saat saya cek database, usernamenya itu keganti menjadi password
<?php
function register_user($nama,$email,$pass){
global $link;
$nama = mysqli_real_escape_string($link, $nama);
$nama = mysqli_real_escape_string($link, $email);
$nama = mysqli_real_escape_string($link, $pass);
$query = "INSERT INTO user (username, email, password) VALUES ('$nama', '$email', '$pass')";
if( mysqli_query($link, $query)){
return true;
}else{
return false;
}
}
function cek_data($nama, $pass){
global $link;
$nama = mysqli_real_escape_string($link, $nama);
$nama = mysqli_real_escape_string($link, $pass);
$query = "SELECT password FROM user";
$result = mysqli_query($link, $query);
$hash = mysqli_fetch_assoc($result)['password'];
if( password_verify($pass, $hash)){
return true;
}else {
return false;
}
}
?>
0
2 Jawaban:
dan register.php
<?php
require_once "core/init.php";
require_once "functions/user.php";
require_once "view/header.php";
?>
<link rel="stylesheet" type="text/css" href="style/regstyle.css">
<br><br><br><center>
<form class="form" action="register.php" method="post">
<?php
if( isset($_POST['submit']) ){
$nama= $_POST['nama'];
$email= $_POST['email'];
$pass= $_POST['password'];
if(!empty(trim($nama)) && !empty(trim($email)) && !empty(trim($pass))) {
if(register_user($nama, $email, $pass)) {
echo '<center><a class="berhasil">BERHASIL</a></center>';
}else{
echo 'gagal daftar';
}
}else {
echo 'tidak boleh kosong';
}
}
?>
<label for="">Username</label><br>
<input class="nama" type="text" name="nama"><br><br>
<label for="">Email</label><br>
<input class="email" type="email" name="email"><br><br>
<label for="">Password</label><br>
<input class="password" type="password" name="password"><br><br><br>
<input class="submit" type="submit" name="submit" value="DAFTAR"><br><br>
<a href="login.php" class="login">LOGIN</a><br><br>
</form></center>
0