为什么表单提交按钮仅在双击时有反应?

发布于 2024-12-03 00:10:45 字数 1781 浏览 0 评论 0原文

所以我有一个像这样的简单登录页面:

   <fieldset>
    <legend>Verification</legend>
   <form method="post" action="authentication.php">


<?php if($_GET['error']==1){
      echo "<p style=\"float: left; \" class=\"criticMsg\">Username or password are wrong</p>";  
    }
    ?>


 <br /><br /> <br /><br />
 <label style="float: left; margin-top: 15px;" for="username">User</label><input    type="text" name="username"></input><br />
 <label for="password">Password</label><input type="password" name="password"></input>  <br />
  <input type="submit" class="globalBtn" value="Enter"></input>
  </form>

    </fieldset>

然后authenticate.php文件是这样的:

 include ('functions.php');

if(valid_details($_POST['username'], $_POST['password'])){
header("Location: ../../storage_update.php?message=1");
}else{
header("Location: login.php?error=1");
}

最后functions.php看起来像这样

include("../connection.php");


$sql = "SELECT user, pass FROM users";
$back = "There is an error. <a href=\"login.php\">Back</a>";
$result = $conn->query($sql) or die($back);

while($row = $result->fetch_object()){

//validates user input

function valid_details($username, $password){
if(isset($username) && $username == $row->user){
   if(isset($password) && $password == $row->pass){
   return true;}
   }


  };
 }

当我输入数据库中提供的正确用户名和密码时,我在url中得到error=1变量,这不是我对正确凭证的期望。但是,如果我快速双击提交按钮,它会让我进入预期的页面,在 url 中返回 message=1,这意味着 valid_credentials 函数工作正常,但为什么按钮会有这样的反应? 编辑 在页面 storage_update.php (登陆页面)中我已经实现了 fancybox jquery 插件。

so I have a simple login page like this:

   <fieldset>
    <legend>Verification</legend>
   <form method="post" action="authentication.php">


<?php if($_GET['error']==1){
      echo "<p style=\"float: left; \" class=\"criticMsg\">Username or password are wrong</p>";  
    }
    ?>


 <br /><br /> <br /><br />
 <label style="float: left; margin-top: 15px;" for="username">User</label><input    type="text" name="username"></input><br />
 <label for="password">Password</label><input type="password" name="password"></input>  <br />
  <input type="submit" class="globalBtn" value="Enter"></input>
  </form>

    </fieldset>

then the authenticate.php file is like this:

 include ('functions.php');

if(valid_details($_POST['username'], $_POST['password'])){
header("Location: ../../storage_update.php?message=1");
}else{
header("Location: login.php?error=1");
}

finally the functions.php looks like this

include("../connection.php");


$sql = "SELECT user, pass FROM users";
$back = "There is an error. <a href=\"login.php\">Back</a>";
$result = $conn->query($sql) or die($back);

while($row = $result->fetch_object()){

//validates user input

function valid_details($username, $password){
if(isset($username) && $username == $row->user){
   if(isset($password) && $password == $row->pass){
   return true;}
   }


  };
 }

When I type the correct username and password provided in the database I get the error=1 variable in the url, which is not what I expect on correct credentials. However if I fastly double click the submit button it gets me on the expected page returning message=1 in the url, so that it means the function valid_credentials is works ok, but why does the button react like that? EDIT In the page storage_update.php (the landing page) I have implemented fancybox jquery plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2024-12-10 00:10:45

你的代码结构真的很奇怪,如果我有办法的话,我会重写大部分代码,无论如何,把它放在一边。目前,您的函数位于 while 循环内,为什么您首先要循环很奇怪,您可以直接在数据库中检查您正在查找的用户。见下文。

include("../connection.php");

function valid_details($username, $password){
    $sql = "SELECT user, pass FROM users";
    $sql .= "WHERE user='".$username."' AND pass='".$password."'"; 
    $back = "There is an error. <a href=\"login.php\">Back</a>";
    $result = $conn->query($sql) or die($back);

    return count( $result ) > 0             
} 

The structure of your code is really odd, if i had my way i would rewrite most of it, anyways, putting that aside. Currently you have your function within a while loop, why you're looping in the first place is bizarre, you can just do a direct check in the database for the user that you are looking for. See below.

include("../connection.php");

function valid_details($username, $password){
    $sql = "SELECT user, pass FROM users";
    $sql .= "WHERE user='".$username."' AND pass='".$password."'"; 
    $back = "There is an error. <a href=\"login.php\">Back</a>";
    $result = $conn->query($sql) or die($back);

    return count( $result ) > 0             
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文