首页 > 解决方案 > 登录尝试显示空白页面后未显示任何错误

问题描述

尝试重定向到空白页面后没有错误显示没有登录

我不明白语法错误或......

<?php

if(isset($_POST['submit'])){
    $message = '';
    $error = '';
    //username and password sent from Form
    $email = trim($_POST['email']);
    $password = trim($_POST['password']);
    
    if($email ==''){
        $error[] = '<p class="error">Please enter Email and Password.</p>';
    }
   
    else {
          $error[] = '<p class="error">Wrong Email and password.</p>';
      }    

    if($user->login($email,$password)){ 

        //logged in return to index page
        header('Location: index.php');
        exit;
        }      
    
    }//end if submit
if(isset($error)){
    foreach($error as $error){
        echo '<p class="error">'.$error.'</p>';
    }
}
?>

<?php if(isset($message)){ echo $message; }?>
<form action="" method="post">  
<p><input type="email" name="email" placeholder="Email " value=""  /></p>
<p><input type="password" name="password" placeholder="Password" value=""  /></p>   
<p><label></label><input type="submit" class="button" name="submit" value="Login"  /></p>
</form> 

标签: php

解决方案


我猜你想要这样?因为您的问题不清楚,请添加更多详细信息

<?php

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

    $errors = '';

    //username and password sent from Form
    $email = trim($_POST['email']);
    $password = trim($_POST['password']);
    
    if($email == '' || $password == ''){

        $errors[] = '<p class="error">Please enter Email and Password.</p>';
    }  

    if($user->login($email,$password)){ 

        //logged in return to index page
        header('Location: index.php');
        exit();
    
    } else {

        $errors[] = '<p class="error">Wrong Email and password.</p>';
    }

    if(!empty($errors)){
        foreach($errors as $error){
            echo '<p class="error">'.$error.'</p>';
        }
    }
}

?>

推荐阅读