我已经安装了XAMPP来模拟我的电脑上的php服务器环境。不幸的是,当我点击提交时,我的html表单将无效。这是html:
<html>
<form>
<form action="http://localhost/New/nn.php" method="post">
Why don't they play poker in the jungle?<br>
<input type="radio" name="jungle" value="treefrog"> Too many tree
frogs.<br>
<input type="radio" name="jungle" value="cheetah"> Too many cheetahs.
<br>
<input type="radio" name="jungle" value="river"> Too many rivers.<br>
<br>
<input type="submit" name="submit" value="Submit"><br>
</form>
</html>
这是php:
<?php
if (isset($_POST['submit'])) {
if (!empty($_POST['jungle'])) {
if ($_POST['jungle']=="cheetah") {echo "You got the right
answer";}
if($_POST['jungle']=="treefrog"){echo "You selected treefrog but
answer is cheetah\n";}
if($_POST['jungle']=="river"){echo "You selected river but
answer is cheetah\n";}
}
else { echo "You did not choose an answer for jungle.\n"; }
}
else { echo "Please submit the form."; }
?>
答案 0 :(得分:0)
在提供的代码中,您有两个表单开始标记:
<form>
<form action="http://localhost/New/nn.php" method="post">
这可能是您问题的根源。
在chome for mac(最新版本)。
inspect
Network
标签并重新加载test.html
),然后转到preview
标签。了解如何使用这两个标签Elements
标签,看看您是如何只有第一个,因此将您发送回同一页面(这是默认操作)