【发布时间】:2018-08-15 01:11:02
【问题描述】:
我对 PHP 非常陌生,我正在尝试在字符串中显示选定单选按钮的值。但是我得到的只是“on”而不是与选择相关的值。任何帮助都会很棒!
<form action="Handle_form_PHP.php" method="post">
<div class= "row">
<div class ="col-25">
<label for="student">Student</label>
</div>
<div class ="col-75">
<input type="radio" name="student" value ="student">
</div>
</div>
<div class= "row">
<div class ="col-25">
<label for="student">Employee</label>
</div>
<div class ="col-75">
<input type="radio" name="student" value = "employee">
</div>
</div>
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
这是我用来打印的 PHP:
// Create a shorthand for the form data:
$fname = $_REQUEST['firstname'];
$lname = $_REQUEST['lastname'];
$address = $_REQUEST['address'];
$state1 = $_REQUEST['state1'];
$state2 = $_REQUEST['state2'];
$student = $_POST['student'];
// Print the submitted information:
echo "<p>Thank you, <b> $student </b>, <b>$fname $lname</b>, for the filling out our survey:<br>
<p>We will Send you your report at: <i>$address</i>, <i>$state1</i><i>$state2</i>.</p>\n";
【问题讨论】:
-
你的表单方法是使用 GET 还是 POST,为什么你只对“学生”使用 $_POST?
-
这是 POST,老实说,我只是在使用教授给我们的内容,而她的代码在所有这些中都使用了 $_REQUEST。我正在搜索单选按钮可能是我的问题并阅读以使用 POST。但这并没有帮助
-
经过 30 分钟的搜索,我才弄明白。我把帖子而不是 POST ...... sigh 对不起!
标签: php post button form-submit radio