如何检查php中是否选中了复选框/单选按钮
我有以下html代码:如何检查php中是否选中了复选框/单选按钮,php,mysql,html,Php,Mysql,Html,我有以下html代码: <tr> <td><label><input type="text" name="id" class="DEPENDS ON info BEING student" id="example">ID</label></td> </tr> <tr> <td> <label> <input type="
<tr>
<td><label><input type="text" name="id" class="DEPENDS ON info BEING student" id="example">ID</label></td>
</tr>
<tr>
<td>
<label> <input type="checkbox" name="yr" class="DEPENDS ON info BEING student"> Year</label>
</td>
</tr>
身份证件
年
但是我不知道如果使用php检查了这些复选框,如何检查它们,然后根据检查的值输出相应的数据
请帮帮我,我在想这样的事情。但这当然行不通,因为我不知道如何将php中的复选框等同于选中的复选框:
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("school", $con);
$id = mysql_real_escape_string($_POST['idnum']);
if($_POST['id'] == checked & $_POST['yr'] ==checked ){
$result2 = mysql_query("SELECT * FROM student WHERE IDNO='$id'");
echo "<table border='1'>
<tr>
<th>IDNO</th>
<th>YEAR</th>
</tr>";
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td>" . $row['IDNO'] . "</td>";
echo "<td>" . $row['YEAR'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($con);
?>
应该是:
$\u在“
firefox的默认设置为“开启”,在其他浏览器中可能有所不同。(感谢大卫)
应该是:
$\u在“
firefox的默认设置为“开启”,在其他浏览器中可能有所不同。(感谢David)尝试以下方法:
if (isset($_POST['yr'])) { ... }
请尝试以下操作:
if (isset($_POST['yr'])) { ... }
必须为复选框指定一个值。如果选中该复选框,则会将该值发送到服务器
if ( $_POST['checkboxname'] == 'checkboxvalue' ) {
}
因为我看不到任何形式:
要将数据发送到服务器,需要在输入元素周围创建一个表单:
<form method="POST" action="myphpscript.php">
YOUR CONTENT HERE
</form>
你的内容在这里
必须为复选框指定一个值。如果选中该复选框,则会将该值发送到服务器
if ( $_POST['checkboxname'] == 'checkboxvalue' ) {
}
因为我看不到任何形式:
要将数据发送到服务器,需要在输入元素周围创建一个表单:
<form method="POST" action="myphpscript.php">
YOUR CONTENT HERE
</form>
你的内容在这里
如果包含一个隐藏字段,该字段的名称和失败值与您希望在post数据中显示的字段名称和失败值相同,则当复选框未返回值(未选中)时,表单上的隐藏控件将显示
echo '<form method="post"><input type="hidden" name="checkdata" value="0">\
<input type="checkbox" name="checkdata" value="1">\
<input name="submitbutton" type="submit"></form>\
</body></html>';
if ($_POST['submitbutton']) {
echo "Value:|".$_POST['checkdata']."|";
}
echo'\
\
\
';
如果($_POST['submitbutton'])){
echo“Value:|”。$_POST['checkdata']。“|”;
}
如果包含一个隐藏字段,该字段的名称和失败值与您希望在post数据中显示的字段名称和失败值相同,则当复选框未返回值(未选中)时,表单上的隐藏控件将显示
echo '<form method="post"><input type="hidden" name="checkdata" value="0">\
<input type="checkbox" name="checkdata" value="1">\
<input name="submitbutton" type="submit"></form>\
</body></html>';
if ($_POST['submitbutton']) {
echo "Value:|".$_POST['checkdata']."|";
}
echo'\
\
\
';
如果($_POST['submitbutton'])){
echo“Value:|”。$_POST['checkdata']。“|”;
}
不应该,输入值未“检查”。因为它没有设置,所以它将是浏览器默认的('On'IIRC,但最好显式设置它)它不应该,输入的值没有“检查”。因为它没有设置,所以它将是浏览器默认设置的(“On”IIRC,但最好是显式设置)这是您的真实密码吗?我希望不是:)这是你的真实密码吗?我希望不是:)