【发布时间】:2015-06-15 01:25:45
【问题描述】:
我创建了一个要求用户选择单选按钮的基本网站。我想要一个 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?");
}
?>
【问题讨论】: