在PHP中按提交按钮时更改页面

在PHP中按提交按钮时更改页面,php,html,Php,Html,当我按下提交按钮“login”时,我希望我的页面转到“frontPage.php”,但它会转到“login.php”,尽管我已经指定了 header("location: frontPage.php"); 在我的login.php中 login.php if (isset($_POST['login'])) { if (empty($_POST["username"]) || empty($_POST["password&quo

当我按下提交按钮“login”时,我希望我的页面转到“frontPage.php”,但它会转到“login.php”,尽管我已经指定了

header("location: frontPage.php");
在我的login.php中

login.php

if (isset($_POST['login'])) {
        if (empty($_POST["username"]) || empty($_POST["password"])) {
            echo "Please fill all fields";
        } else {
            $usernameinput = filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING);
            $passwordinput = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
            
            $query = "SELECT * FROM users WHERE username = :username";
            $stmt  = $conn->prepare($query);
            $stmt->execute(array(
                'username' => $usernameinput
            ));
            $count = $stmt->rowCount();
            
            if ($count > 0) {
                
                while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
                    
                    if (password_verify($passwordinput, $result["password"])) {
                        $_SESSION["username"] = $usernameinput;
                        break;
                    }
                }
                header("location: frontPage.php");
            } else {
                header("location: index.php");
            }
        }
    }

登录
用户名:
密码:
提交

您缺少“提交”按钮上的“名称”属性。它应该具有name=“login”属性


您的所有输入也缺少name属性。复制缺少名称属性的id属性的内容。

您缺少所有输入的属性名称 试试这个


登录
用户名:
密码:
提交

您的
输入
没有
名称
,因此无法通过PHP访问。下面是一个很好的示例:答案有一个“编辑”按钮…您不需要用注释补充内容:-)
<body>
    <div class="container">
        <form id="form" class="form" method="POST" action="login.php">
            <h2>Log In</h2>
            <div class="form-control">
                <label for="username">Username:</label>
                <input type="text" id="username" placeholder="Enter Username">
            </div>
            <div class="form-control">
                <label for="password">Password:</label>
                <input type="password" id="password" placeholder="Enter Password">
            </div>
            <button id="login">Submit</button>
        </form>
    </div>
</body>
<body>
    <div class="container">
        <form id="form" class="form" method="POST" action="login.php">
            <h2>Log In</h2>
            <div class="form-control">
                <label for="username">Username:</label>
                <input type="text" id="username" name="username" placeholder="Enter Username">
            </div>
            <div class="form-control">
                <label for="password">Password:</label>
                <input type="password" id="password" name="password" placeholder="Enter Password">
            </div>
            <button id="login" type="submit" name="login">Submit</button>
        </form>
    </div>
</body>