How to check if a checkbox/ radio button is checked in php

Posted by user225269 on Stack Overflow See other posts from Stack Overflow or by user225269
Published on 2010-04-26T09:10:41Z Indexed on 2010/04/26 9:13 UTC
Read the original article Hit count: 174

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql