How can I display a checkbox checked based on value in the database using php

02nd, January 2018 By

To Show the chechbox checked by fetching value from database table you need to follow these instructions:

Fetch data from database using mysql_query


$result_myquery = mysql_query("select cad,username,class from user where id=745917");

Here you will get data from table in array and you can use this for showing checkbox checked for example:

  <input name="cad" type="checkbox" id="cad" <?php if($result1['cad']=='true'){ ?> checked="checked" <?php } ?>/>

if $result1[‘cad’] gives value as true then it will show this checkbox checked you can also do this for radio buttons for example:

<input type="radio" name="cad" <?php if($result1['cad']=='yes'){ ?> checked="checked" <?php } ?> id="fddf"  value="yes" />

Leave a Reply

Your email address will not be published. Required fields are marked *