doulang6013 2015-04-06 22:00
浏览 87
已采纳

php echo在if else语句中不起作用[关闭]

I have tried to add die("The passwords don't match"); also insted of echo. But this still seems to not do anything at all when register is clicked. The variable names match the ones in the contact form perfectly. I can only think of one thing. Might sound funny It it because I'm already logged in (registered)?. I'm sorry if thsi question has been answered but I did not see any answer that helped me with someone in a similar situation. Cheers!

<?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;

 }

?>
  • 写回答

1条回答 默认 最新

  • doujian1050 2015-04-06 22:39
    关注

    Based on your code, your main issue is that you are missing an equal sign in your form name="submit". Here is a reorganization of what you have with notations:

    // 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; 
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法