如何检查一个复选框/单选按钮是否在PHP中被选中

问题描述:

我有这个html代码:

I have this html code:

<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 ,然后根据检查的值输出相应的数据。

But I don't have any idea on how do I check this checkboxes if they are checked using php, and then output the corresponding data based on the values that are checked.

请帮忙,我在想这样的事情。但当然这是行不通的,因为我不知道如何将php中的复选框等同于checkbox:

Please help, I'm thinking of something like this. But of course it won't work, because I don't know how to equate checkboxes in php if they are checked:

<?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);
?> 


您必须为您的复选框赋予一个值。这个值被发送到服务器,以防复选框被选中。

You must give your checkboxes a value. This value gets send to the server, in case the checkbox is checked.

if ( $_POST['checkboxname'] == 'checkboxvalue' ) {

}

由于我看不到表单:
要将数据发送到服务器,需要输入元素的一个表单:

Since I see no form: To send the data to the server, you need a form around your input elements:

<form method="POST" action="myphpscript.php">
    YOUR CONTENT HERE
</form>