首页 > 解决方案 > 提交错误的表单时网页刷新到顶部

问题描述

如果我输入了不正确的电子邮件地址或密码,我的网站会刷新到页面顶部并看到此错误

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>";

        }
    }

?>

标签: javascriptphpjqueryhtmlcss

解决方案


推荐阅读