我不知道自己在做什么错。我需要建议或修改我的代码。我无法注册用户。当我按下注册按钮时,它将带我到空白页。数据库内部也没有任何注册。我只需要对我的代码有一些反馈。谢谢。
$name = htmlentities(mysqli_real_escape_string($conn,$_POST['user_name']));
$pass = htmlentities(mysqli_real_escape_string($conn,$_POST['user_pass']));
$email = htmlentities(mysqli_real_escape_string($conn,$_POST['user_email']));
$country = htmlentities(mysqli_real_escape_string($conn,$_POST['user_country']));
$gender = htmlentities(mysqli_real_escape_string($conn,$_POST['user_gender']));
$rand = rand(1, 2);
if(empty($name)){
echo " <div style='color:red;
text-align:center;
font-size: 23px;'>
<strong>name can't be emoty.</strong>
</div>";
}elseif (strlen($pass)<8){
echo " <div style='color:red;
text-align:center;
font-size: 23px;'>
<strong>Check your email and password!</strong>
</div>";
exit();
}else {
$check_email = "SELECT * FROM users WHERE user_email='$email'";
$run_email = mysqli_query($conn,$check_email);
$check = mysqli_num_rows($run_email);
if($check==1){
echo "<div style='color:red;
text-align:center;
font-size: 23px;'>
<strong>email already exists! try again</strong>
</div>";
header('refresh:4; url="signup.php"');
exit();
}
if($rand == 1)
$profile_pic = "images/deadpool.png";
else if($rand == 2)
$profile_pic = "images/person.jpg";
$insert = "INSERT INTO users (user_name,user_pass,user_email,user_profile,user_country,user_gender) VALUES ('$name','$pass','$email','$profile_pic','$country','$gender')";
$query = mysqli_query($conn,$insert);
if($query){
echo " <div style='color:green;
text-align:center;
font-size: 23px;'>
<strong>congratulation! $name you are registered</strong>
</div>";
header('refresh:4; url="signin.php"');
exit();
}
else {
echo "<script>alert('Registration failed, try again!')</script>";
echo "<script>window.open('signup.php','_self')</script>";
}
}
}
?>`