php echo 在 if else 语句中不起作用

php echo not working in if else statement

我试过加die("The passwords don't match");也安装了回声。但是当点击注册时,这似乎仍然没有做任何事情。变量名称与联系人表单中的变量名称完全匹配。我只能想到一件事。可能听起来很有趣是因为我已经登录(注册)了吗?如果这个问题已经得到回答,我很抱歉,但我没有看到任何对处于类似情况的人有帮助的答案。干杯!

<?php
require('inc/phpfunctions.php');

if(isset($_POST['submit'])){

//perform the verification
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];

if ($email1 == $email2){
    if($pass1 == $pass2){
    //All good. Carry On.
    }else{
        echo "Sorry your passwords do not match. <br />";
        exit();
     }
    }else{
        echo "Sorry your email's do not match<br /><br />";
}



 }else{

 $form = <<<EOT

 <form action="register.php" method="POST">
 First Name: <input type= "text" name="name" /><br />
 Last Name: <input type= "text" name="lname" /><br />
 Username: <input type= "text" name="uname" /><br />
 Email: <input type= "text" name="email1" /><br />
 Confirm Email: <input type= "text" name="email2" /><br />
 Password: <input type= "password" name="pass1" /><br />
 Confirm Password: <input type= "password" name="pass2" /><br />
 <input type="submit" value="Register" name"submit" />
 </form>
EOT;

echo $form;

 }

?>

根据您的代码,您的主要问题是表单中缺少等号 name="submit"。这是对符号的重组:

// Establish fail by default
$success    =   false;
if(isset($_POST['submit'])){

        // Create a function that will match input values
        function MatchVars($var1,$var2)
            {
                if(empty($var1) || empty($var2))
                    return 0;

                return ($var1 == $var2)? 1 : 0;
            }

        // Store error/success
        $validate['email']  =   MatchVars($_POST['email1'],$_POST['email2']);
        $validate['pass']   =   MatchVars($_POST['pass1'],$_POST['pass2']);
        // Check each for individual error
        if($validate['email'] != 1)
            echo 'Emails do not match!';
        if($validate['pass'] != 1)
            echo 'Passwords do not match!';

        // Assign success or fail based on the sum of the validate array
        // Less than 2 is fail. This will overwrite the first established
        // instance of the $success variable
        $success    =   (array_sum($validate) == 2)? true:false;
    }

if($success == false) {
        // the name="submit" is missing and equal sign
        // Since you are basing your forward movement on that variable
        // if it's "broken," the if/else will not work
        $form = <<<EOT
<form action="" method="POST">
First Name: <input type= "text" name="name" /><br />
Last Name: <input type= "text" name="lname" /><br />
Username: <input type= "text" name="uname" /><br />
Email: <input type= "text" name="email1" /><br />
Confirm Email: <input type= "text" name="email2" /><br />
Password: <input type= "password" name="pass1" /><br />
Confirm Password: <input type= "password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;

        echo $form; 
    }