javascript - 提交错误的表单时网页刷新到顶部
问题描述
如果我输入了不正确的电子邮件地址或密码,我的网站会刷新到页面顶部并看到此错误
Incorrect email and Pass
我必须向下滚动到我的表单所在的位置才能看到详细的错误。
我想阻止我的页面进入顶部。
我在这里搜索了解决方案,但找不到任何东西。
HTML 代码:
<body>
<form method="post" style="margin-right:450px;">
<table align="center" cellspacing="3px;">
<tr>
<td>
<input style="border:1px #666 solid; border-radius: 4px; width: 180px; padding: 12px 20px; font-size:18px;" type="email" name="mail" required placeholder="Your Email">
</td>
<td>
<input style="border:1px #666 solid; border-radius: 4px; width: 180px; padding: 12px 20px; font-size:18px;" type="password" name="pass" required placeholder="Your Password">
</td>
</tr>
</table>
<br><br>
<button class="button button3" type="submit" name="log" style="color:#FFF; text-align:center; margin-left:70px;">Log In</button></td>
</form>
</body>
PHP代码:
<?php
$con=mysqli_connect("localhost","root","","form_data");
if(isset($_POST['log']))
{
$_SESSION['mail'] = $_POST['mail'];
$email = $_POST['mail'];
$Password = $_POST['pass'];
$query = mysqli_query($con,"select * from registration where (User_name = '$email' or Email= '$email') and Password = '$Password' ");
$check = mysqli_num_rows($query);
if($check == 1)
{
echo "<h1> User Login <h1>";
header("location:exam.php");
}
else
{
echo "<div class='error'> ";
echo "!! Invalid Username Or Password !!";
echo "</div>";
}
}
?>
解决方案
推荐阅读
- ruby - Ruby 错误发生时是否会沿调用链向上传播?变得奇怪的行为
- soap - WSDL2APEx 字段缺失
- javascript - 根据vuejs中的选定值隐藏显示div
- c++ - C++ - 以面向性能的方式读取日志级别
- dns - 当我在 DNS 中添加具有相同域名和不同目标的两个 (A) 行时会发生什么
- single-sign-on - Keycloak 使用工件绑定抛出 400 Bad request 异常
- time-series - 解释 auto.arima() 的输出
- ios - SwiftUI:NavigationView 中的 TextField 无法编辑
- android - Android Work Manager Retrofit libc:致命信号 11 Android 6
- python - 使用正则表达式组织电话号码