PHP代码显示仍然有错误,即使所有的输入是正确的.我的代码有什么问题?


PHP code show still with error even if all input are correct. What's wrong with my code?

我在php中做一个简单的注册系统,然而,即使我输入所有正确的细节,它不去数据库,它仍然回声withError = 1,即使所有条目都是正确的。这是我的php代码。

<?php
if($submit)
{
    if ($fullname && $email && $username && $password && $conPassword)
    {
        if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9'._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9'._-]+)+$/", $email))
        {
            $query1 = "SELECT Email FROM tbl_userAccounts WHERE Email='$email'";
            $result1 = mysqli_query($mysqli,$query1) or die(mysqli_error());
            if (mysqli_num_rows($result1) < 0)
            echo "email is already used. ";
            $withError = true;
        }
        else
        {
            echo "invalid email address. ";
            $withError = true;
        }
        if (strlen($username) < $charMinimum)
        {
            echo "minimum of 6 characters for username. ";
            $withError = true;
        }
        else
        {
            $query2 = "SELECT Username FROM tbl_userAccounts WHERE Username='$username'";
            $result2 = mysqli_query($mysqli,$query2) or die(mysqli_error());
            if (mysqli_num_rows($result2) < 0)
            {
                echo "username is already used. ";
                $withError = true;
            }
        }
        if($password == $conPassword)
        {
            echo $withError;
            if($withError == false)
            {
                if (strlen($password) < $charMinimum)
                {
                    echo "minimum of 6 characters for password. ";
                    $withError = true;
                }
                else
                {
                    $query3 = "INSERT INTO tbl_userAccounts VALUES ('', '$fullname', '$username', '$password','$date', '$email')";
                    $result3 = mysqli_query($mysqli,$query3) or die(mysqli_error());
                    if($result3 && $withError == false)
                    echo "account has been successfully registered!";
                    else
                    echo "failed registration. ";
                }
            }
        }
        else
        {
            echo "passwords do not match. ";
            $withError = true;
        }
    }
}
else
{
    echo "fill out all fields. ";
    $withError = true;
}
?>

您忘记包装嵌套的IF语句了。

    if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9'._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9'._-]+)+$/", $email))
    {
        $query1 = "SELECT Email FROM tbl_userAccounts WHERE Email='$email'";
        $result1 = mysqli_query($mysqli,$query1) or die(mysqli_error());
        if (mysqli_num_rows($result1) < 0) {
            echo "email is already used. ";
            $withError = true;
        }
    }
if (mysqli_num_rows($result1) < 0)
{
     echo "email is already used. ";
     $withError = true;
}

你忘了用大括号