我创建了一个基本网站,要求用户选择一个单选按钮。我想要一个 PHP 文件来检索所选单选按钮的值并做出相应响应,但该文件当前不产生任何输出。我现在使用的代码有什么问题吗?为什么我的 PHP 文件无法正确检索单选按钮值?
索引.html:
<form method="POST">
<input type="radio" name="MyRadio" value="First" checked>First<br> //This one is automatically checked when the user opens the page
<input type="radio" name="MyRadio" value="Second">Second
</form>
<form method="GET" action="Result.php">
<input type="submit" value="Result" name="Result"> //This button opens Result.php
</form>
结果.php:
<?php
$radioVal = $_POST["MyRadio"];
if($radioVal == "First")
{
echo("You chose the first button. Good choice. :D");
}
else if ($radioVal == "Second")
{
echo("Second, eh?");
}
?>
您为一般输入元素使用两种单独的表单,其中一种仅包含提交按钮。
在第一个表单中包含提交按钮,它应该可以正常工作:
<form method="POST" action="Result.php">
<input type="radio" name="MyRadio" value="First" checked>First<br> //This one is automatically checked when the user opens the page
<input type="radio" name="MyRadio" value="Second">Second
<input type="submit" value="Result" name="Result"> //This button opens Result.php
</form>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)