我在test.php
中有这段代码。
出于某种原因,即使我点击提交,我也没有收到它发布的消息。有谁能解释为什么?我怎样才能让它发挥作用。
<body>
<form action="" method="post">
<input type="text" id="inp" />
<input type="submit" value="submit" />
</form>
<?php
if (isset($_POST['submit'])) {
echo "posting";
}
?>
</body>
答案 0 :(得分:3)
为输入命名:
<input type="submit" name="submit" value="submit" />
答案 1 :(得分:1)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo "posting";
}
答案 2 :(得分:0)
试试这个:
<body>
<form action="" method="post">
<input type="text" id="inp" />
<input type='hidden' name='submit' value=''>
<input type="submit" value="submit" />
</form>
<?php
if (isset($_POST['submit'])) {
echo "posting";
}
?>
</body>