错误信息不会显示在页面上

时间:2017-04-22 20:20:31

标签: php

如果用户尝试使用未经确认的帐户登录或密码不正确,则会在页面重新加载时提供一个小错误框告诉他们。

当运行登录脚本并尝试登录尚未确认的帐户时,我将使用此URL返回

signin.php?错误= no_confirm

当页面重新加载但是它有正确的URL但没有任何反应!我是否正确设置了以下代码?

<?php
$error = $_GET['error'];

echo $error;

 if ($error) {
 if($error == 'mismatch') {
    echo "
<div class='alert alert-danger' role='alert'>
  <strong>Oh snap!</strong> You need to confirm your account before you sign 
in!
</div>
";
} elseif ($error == 'no_confirm') {
echo "
<div class='alert alert-danger' role='alert'>
  <strong>Oh snap!</strong> Youre username or password was incorrect.
</div>
";
} else {
echo "";
}
 } else {
    echo "nov";
 }

?>

4 个答案:

答案 0 :(得分:1)

删除if ($error) { }并将其更改为if(isset($error)) { }

确保您的GET请求正确:

.php?error=mismatch

答案 1 :(得分:0)

好的,你不要在utf-8中设置你的页面,它就像一个文本文件试着再次保存它

答案 2 :(得分:0)

你好你的代码对我有用,但我也为你写了替代方法,你可以这样试试:

<?php
$error = $_GET['error'];

echo $error;


if (preg_match('/mismatch/',$error))
{
    echo "<div class='alert alert-danger' role='alert'>
  <strong>Oh snap!</strong> You need to confirm your account before you sign 
in!
</div>";
}

if (preg_match('/no_confirm/',$error))
{
    echo "<div class='alert alert-danger' role='alert'>
  <strong>Oh snap!</strong> Youre username or password was incorrect.
</div>";
}
?>

答案 3 :(得分:-1)

尝试使用双&#34;而不是单一的&#39;     $ error = $ _GET [&#34;错误&#34;];