登录时出现错误消息(HTML和php)

问题描述:

我尝试编写可以显示错误消息的登录过程。在HTML我的登录表单是这样的:对于登录时出现错误消息(HTML和php)

<form id="login" action="data/login.php" method="post"> 
    <H2>Rgister</H2> 
    Your login and password: 
    <br><br> 
    <div id="login-name" style="margin-top:20px;">Login:</div><div id="login-fld" style="margin-top:20px;"><input name="username" class="form-login" title="Username" value="" size="30" maxlength="2048" /></div> 
    <div id="login-name">Pass:</div><div id="login-fld"><input name="password" type="password" class="form-login" title="Password" value="" size="30" maxlength="2048" /></div> 
    <br><br><br> 
    <input type="image" src="obr/login-klw.png" alt="Submit" width="103" height="42" style="margin-left:90px;"> 
    <br><br> 

    <?php if ($_GET["log_err"]) { if ($_GET["rsn"] == "pass") { ?> 
    <html><body><h3>Error no 1</h3></body></html> 
    <?php } else { ?> 
    <html><body><h3>Error no 2</h3></body></html> 
    <?php } exit; } ?> 
</form> 

和PHP代码:

... [ question to the database and return in $result object ] ... 

     if ($result->num_rows == 0) { 
      setcookie('logged_in', false, time() + 600, '/'); 
      die(header("location:../index.html?log_err=true&powod=pass")); 
     } 
     else { 
      setcookie('logged_in', $_POST['username'], time() + 600, '/'); 
      header("Location: /AAA/app.html"); 
     } 
    } 
    else { 
     setcookie('logged_in', false, time() + 600, '/'); 
     die(header("location:../index.html?log_err=true&powod=empty")); 
} 

和两个消息(“错误号1”和“错误号2”)我看,每次我加载 此页。我不知道为什么以及如何调试这部分代码。任何人都可以帮助我?

问题是,这种形式看起来是这样的: enter image description here

我看到错误的按摩所有的时间。

+0

请粘贴整个代码 – Blueblazer172

+0

为什么使用$ _GET? –

+1

你把'

.....'里面的'
'。 – Banzay

解决:第一个文件名应为 “的index.php” 不 “的index.html”,第二个代替:

<?php if ($_GET["log_err"]) { if ($_GET["rsn"] == "pass") { ?> 

应该是:

<?php if (isset($_GET['log_err'])) if ($_GET["log_err"]) { if ($_GET["rsn"] == "pass") { ?> 

在应用程序启动有没有$ _GET,所以它的存在应该先测试。 谢谢你的回复。

+0

停止使用'$ _GET',改用SESSIONs。 – Martin

这是你会一遍又一遍地面对的问题。在开发模式下学习将变量转储到屏幕上,以便在服务器正在理解的内部进行对等。

以最简单的形式,你所要做的就是在你的代码下面。

<?php var_dump($_GET); ?>

那么,也许,var_dump($_GET["log_err"]);等。

其他正确的答案不能承受,哦,检查你没有var_dump()语句在你发布你的代码之前徘徊。

祝你好运。

+0

谢谢你的信息 – Tad