[英]Checking which radio button is selected in PHP
I have an HTML page that contains two radio buttons ("yes" and "no") along with a submit button. 我有一个HTML页面,其中包含两个单选按钮(“是”和“否”)以及一个提交按钮。
How can I specify that I want to execute a PostgreSQL query ONLY if the submit button is pressed AND the "yes" radio button is selected? 如果按下提交按钮并且选择了“是”单选按钮,我该如何指定我只想执行PostgreSQL查询?
Your radio buttons need to have the same name
, so check the value that is submitted for that field: 您的单选按钮需要具有相同的
name
,因此请检查为该字段提交的值:
if ($_POST['radio'] == 'Yes')
{
// Execute query
}
Given HTML like this 给出像这样的HTML
<form action="foo.php" method="post">
<label for="yesno_yes">
<input type="radio" name="yesno" value="yes" id="yesno_yes"> Yes
</label>
<label for="yesno_no">
<input type="radio" name="yesno" value="no" id="yesno_no"> No
</label>
<input type="submit" name="submit_btn" value="Submit">
</form>
You can check using this 你可以用它来检查
<?php
if (isset($_POST['submit_btn'], $_POST['yesno']) && $_POST['yesno'] == 'yes') {
// do stuff here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.