3 回答

TA贡献1816条经验 获得超6个赞
您应该首先为输入类型密码或按钮添加名称属性值,如下所示
<div id=continue>
<form action="request.php" method="post">
<input class="input-field" type="password" name="password" placeholder="Your passphrase" />
<button class="button" name="submit" value="submit" style="vertical-align:middle"><span>Confirm</span></button>
</form>
</div>
之后你的php代码应该是这样的
<?php
if(isset($_POST['submit']))
{
$pass = $_POST['password'];
if ($pass == "password")
{
include "correct.html";
}
else
{
echo "Password incorrect";
}
}
?>

TA贡献1852条经验 获得超1个赞
这是你必须具备的:form
<div id=continue>
<form action="request.php" method="post">
<!-- Note that input and button are under the SAME <form> -->
<input class="input-field" type="password" name="password" placeholder="Your passphrase" />
<!-- Note `name` attributes of `button` and `input` -->
<button class="button" name="button" value="submit" style="vertical-align:middle"><span>Confirm</span></button>
</form>
</div>
在服务器上:
<?php
// for debugging purposes, remove when you want
print_r($_POST);
// as 'password' is now NAME of INPUT, `$pass` stores the value from the INPUT
$pass = $_POST['password'];
if ($pass == "password")
{
include "correct.html";
}
else
{
echo "Password incorrect";
}

TA贡献1864条经验 获得超6个赞
您应该阅读有关 PHP 中的表单提交的信息。在此特定实例中,您的表单未作为按钮需要提交属性提交提交,即 .<button type="submit"
此外,要调试 post 数据,可以使用 。var_dump($_POST); die();
- 3 回答
- 0 关注
- 127 浏览
添加回答
举报