提交按钮只是刷新 php

submit button just refreshes php

<form method="POST">
    <div class="form-outline form-white mb-4">
  <input type="password" name="password" class="form-control" required/>
  <label class="form-label" for="form">Pass</label>
</div>
    <button type="Submit" value="send" class="btn transparent btn-block" style="color: white;">Submit</button>
  </form>

   if (isset($_POST['submit'])) {
      $password=$_POST['password'];

      if ($password=='password') {
        header("location:ari.html");
        exit();
      }
      else
        echo "Incorrect.";
    }

我目前正在开始 php,我正在尝试使用登录方法,但每当我按下提交按钮时,我的代码都会刷新,并且不会移动到我指定的下一页。 (位置:ari.html) 如果我能在我做错的地方得到帮助,那将是非常感谢的。

你应该考虑在表单标签中使用 action 属性并指向一些 POST url 来检索你的数据 使用操作线 this

<form method="POST" action="/ari.php">

提交按钮刷新页面没有动作属性它只是指向当前URL如果你不填写它

看看这一行:

<form method="POST">

发生的事情是,当您提交表单时,它会将数据发送到同一页面。

这一行:

if (isset($_POST['submit'])) 我没有找到带有 name='submit' 属性的标签。你应该把它放在你的提交按钮中。

如果您想将其发送到另一个页面,请使用表单标记中的 action 属性并将您的数据指向该页面,如 action=yourpage.php

<form method="POST" >
    <div class="form-outline form-white mb-4">
  <input type="password" name="password" class="form-control" required/>
  <label class="form-label" for="form">Pass</label>
</div>
    <button type="Submit" name="submit" value="send" class="btn transparent btn-block" style="color: white;">Submit</button>
  </form>
<?php
   if (isset($_POST['submit'])) {
    echo $password=$_POST['password']=='password'?header("location:ari.html"):"Incorrect.";
}
?>

已更新此代码并且对我来说工作正常...希望你得到答案