How to check if a checkbox/ radio button is checked in php
- by user225269
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>
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.
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);
?>