Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';无法在PHP中获取错误消息_Php_Include - Fatal编程技术网

Can';无法在PHP中获取错误消息

Can';无法在PHP中获取错误消息,php,include,Php,Include,我有一个登录表单index.php,它的输入是ID和密码 login\u user.php 它接受数据 如果凭据正确,则用户将正确路由到主页。但是,当用户输入错误的登录详细信息时,我必须检查数据库中存储的值。因此,我认为应该在login\u user.php中使用一些变量,然后将其包含在index.php中,并在div中打印错误。到目前为止,我做了这个代码 <div class="alert alert-warning alert-dismissible" role=&

我有一个登录表单
index.php
,它的输入是ID和密码
login\u user.php
它接受数据

如果凭据正确,则用户将正确路由到主页。但是,当用户输入错误的登录详细信息时,我必须检查数据库中存储的值。因此,我认为应该在
login\u user.php
中使用一些
变量
,然后
将其包含在
index.php
中,并在
div
中打印错误。到目前为止,我做了这个代码

<div class="alert alert-warning alert-dismissible" role="alert" id="alert_login_error">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
           <span aria-hidden="true">&times;</span>
        </button>
        <strong id="error_flag">
            Invalid Login Details
        </strong>
</div>
  <?php
    include "login_user.php";
    if (empty($error)) {
      echo "<script>  $('#alert_login_error').hide(); console.log('empty');</script>";
    }
    else {
      echo "<script>  $('#alert_login_error').show();console.log('not empty');</script>";
    }
 ?>
此代码的作用是什么

加载
index.php
时,将隐藏定义错误的
div
。这个很好用

但当用户输入错误的登录输入时。然后
div
也被设置为隐藏


我不明白我在哪里犯了错误。如果还需要什么,请询问,以便我能提供。提前感谢

使用
标题('location:index.php')
代码立即重定向用户;一旦发生这种情况,
$error
将在干净页面加载的情况下被清除,这意味着您的
if(empty($error))
条件将始终计算为
true

您将立即使用
标题('location:index.php')
代码重定向用户;一旦发生这种情况,
$error
将在干净页面加载的情况下被清除,这意味着您的
if(empty($error))
条件将始终计算为
true

您将立即使用
标题('location:index.php')
代码重定向用户;一旦发生这种情况,
$error
将在干净页面加载的情况下被清除,这意味着您的
if(empty($error))
条件将始终计算为
true

您将立即使用
标题('location:index.php')
代码重定向用户;一旦发生这种情况,
$error
将在干净页面加载的情况下被清除,这意味着您的
if(empty($error))
条件将始终计算为
true

我个人使用$\u会话变量通过PHP脚本管理错误

你的div是

{$\u会话['error']}

在你展示它之后就杀了它

这是herdoc语法。对不起,如果你不习惯的话

这样,您就不必管理show/hide div,因为如果
$\u SESSION['error']
为空,div将为空

注意:我不知道这是否是一个好的解决方案,但至少是一个有效的解决方案

因此,您的PHP脚本应该是:

 if ($num_rows > 0) {
          #User is redirected to Home Page if details are correct
          #If the password is wrong then in a function
           $_SESSION['error'] = "Invalid password";
           header('Location: index.php');
 }
 else {
          $_SESSION['error'] = "Invalid Login details";
          header('Location: index.php');
 }

我个人使用$\u会话变量通过PHP脚本管理错误

你的div是

{$\u会话['error']}

在你展示它之后就杀了它

这是herdoc语法。对不起,如果你不习惯的话

这样,您就不必管理show/hide div,因为如果
$\u SESSION['error']
为空,div将为空

注意:我不知道这是否是一个好的解决方案,但至少是一个有效的解决方案

因此,您的PHP脚本应该是:

 if ($num_rows > 0) {
          #User is redirected to Home Page if details are correct
          #If the password is wrong then in a function
           $_SESSION['error'] = "Invalid password";
           header('Location: index.php');
 }
 else {
          $_SESSION['error'] = "Invalid Login details";
          header('Location: index.php');
 }

我个人使用$\u会话变量通过PHP脚本管理错误

你的div是

{$\u会话['error']}

在你展示它之后就杀了它

这是herdoc语法。对不起,如果你不习惯的话

这样,您就不必管理show/hide div,因为如果
$\u SESSION['error']
为空,div将为空

注意:我不知道这是否是一个好的解决方案,但至少是一个有效的解决方案

因此,您的PHP脚本应该是:

 if ($num_rows > 0) {
          #User is redirected to Home Page if details are correct
          #If the password is wrong then in a function
           $_SESSION['error'] = "Invalid password";
           header('Location: index.php');
 }
 else {
          $_SESSION['error'] = "Invalid Login details";
          header('Location: index.php');
 }

我个人使用$\u会话变量通过PHP脚本管理错误

你的div是

{$\u会话['error']}

在你展示它之后就杀了它

这是herdoc语法。对不起,如果你不习惯的话

这样,您就不必管理show/hide div,因为如果
$\u SESSION['error']
为空,div将为空

注意:我不知道这是否是一个好的解决方案,但至少是一个有效的解决方案

因此,您的PHP脚本应该是:

 if ($num_rows > 0) {
          #User is redirected to Home Page if details are correct
          #If the password is wrong then in a function
           $_SESSION['error'] = "Invalid password";
           header('Location: index.php');
 }
 else {
          $_SESSION['error'] = "Invalid Login details";
          header('Location: index.php');
 }

您在这两种情况下都设置了
$error
,因此
empty($error)
将永远不会为真。打印输出后不能调用
header()
。在包含
login\u user.php
之前,请先打印
,这样那些标题调用就不会起任何作用。@Barmar,但如果用户输入错误,我需要重定向到
login.php
页面。所以我用这个
header()
我明白这一点。您只需重新组织代码,这样它就不会首先打印DIV。@xNeyte如果用户输入了正确的ID但密码错误,那么我必须告诉用户输入了错误的密码。因此我使用了此选项。您在这两种情况下都设置了
$error
,因此
empty($error)
将永远不会为真。您无法调用
header()
打印输出后。在包含
login\u user.php
之前,请先打印
,这样那些标题调用就不会起任何作用。@Barmar,但如果用户输入错误,我需要重定向到
login.php
页面。所以我用这个
header()
我明白这一点。您只需重新组织代码,这样它就不会首先打印DIV。@xNeyte如果用户输入了正确的ID但密码错误,那么我必须告诉用户输入了错误的密码。因此我使用了此选项。您在这两种情况下都设置了
$error
,因此
empty($error)
将永远不会为真。您无法调用
header()
打印输出后。在包含
login\u user.php
之前,请先打印
,这样那些标题调用就不会起任何作用。@Barmar,但如果用户输入错误,我需要重定向到
login.php
页面。所以我使用这个
header()
我理解