为什么表单提交按钮仅在双击时有反应?
所以我有一个像这样的简单登录页面:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码结构真的很奇怪,如果我有办法的话,我会重写大部分代码,无论如何,把它放在一边。目前,您的函数位于 while 循环内,为什么您首先要循环很奇怪,您可以直接在数据库中检查您正在查找的用户。见下文。
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.