php - 登录尝试显示空白页面后未显示任何错误
问题描述
尝试重定向到空白页面后没有错误显示没有登录
我不明白语法错误或......
<?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
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>';
}
}
}
?>
推荐阅读
- c# - OnAuthorizationAsync 中的 Cancellationtoken
- javascript - 无效的组件名称:“pages/product/_slug.vue”。组件名称应符合 html5 规范中的有效自定义元素名称
- excel - 执行从 1 到 LastRow 的循环
- android - 如何在 Android 10 (Android Q) 中隐藏作用域目录的子文件夹?使用媒体商店?
- php - 未捕获的错误:调用未定义的函数 odbc_connect()
- c# - Blazor 中的网络凭据
- jquery - 计算字段输入
- python - 使用列表理解从字符串中删除所有元音
- memory - 数组的物理内存地址是否也像虚拟地址一样按顺序存储?
- django - 带有自我日期列的 djang orm 过滤器