执行多个if条件时出错 [英] Error when executing multiple if conditions
问题描述
嗨!这是usersignup.php代码。所以我想确认两个密码是否匹配,以及我想让我的用户名成为唯一数据。到目前为止,用户名的代码运行良好但代码检查两个密码是否匹配,在php页面显示为空白的情况下不起作用
所以实际结果应该是警报说两个密码都不匹配
在关于检查密码的if语句下我试过其他代码,比如
' echo密码不匹配!;',它完美运行
所以我想如果警报函数或if语句的代码有错误。
我的尝试:
Hi! This is the usersignup.php codes. So i want to confirm if both password match or not as well as i wanted to make my username a unique data. So far the codes for username works well but codes on checking if both passwords match, does not work where the php page appears blank
so the actual outcome should be an alert saying that "both passwords don't match"
Under the if statement on checking the password i have tried on other codes like
'echo "Passwords don't match!";', it works perfectly
so i guess if there is error on the codes for the alert function or on the if statement.
What I have tried:
<?php
include("conn.php");
//retreive data from register.html
$username = $_POST['username'];
$password = $_POST['password'];
$confirmpassword = $_POST['password2'];
$email = $_POST['email_address'];
$query = "SELECT * FROM users WHERE username='$username'";
$result = mysqli_query($con, $query) or die(mysqli_error($con));
$count = mysqli_num_rows($result);
if ($password !== $confirmpassword) {
echo "<script>window.alert('Passwords don't match!'); ";
die("window.history.go(-1);</script>");
}else if ($count>0) {
echo "<script>alert('Sorry! Username already exist!'); ";
die("window.history.go(-1);</script>");
}
$sql = "Insert into users (firstname,lastname,username,email,dob,password)
VALUES ('$_POST[first_name]','$_POST[last_name]','$username','$email','$_POST[dob]','".md5($password)."');";
mysqli_query($con, $sql);
//echo $sql
if(mysqli_affected_rows($con)<=0)
{
echo "<script>alert('Unable to register ! \\nPlease Try Again!');";
die("window.history.go(-1);</script>");
}
echo "<script>alert('Register Successfully!Please login now!');";
echo "window.location.href='Login.html';</script>";
?>
推荐答案
username =
username =
_POST ['username'] ;
_POST['username'];
password =
password =
这篇关于执行多个if条件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!