tags:

views:

57

answers:

3

How do I get to get the values of checkboxes from mysql database, for example if stat6 is dependent, then when I try to fetch the corresponding record using a primary key. Then if the stat6 is checked when I first added the record. It must also be checked when I update. But its not the case. How do I fix this?

<td></td>
<input type='hidden' name="stats6" value="0">
<td><input name="stats6" type="checkbox" id="dep"  value="<?php echo $row["STAT6"]; ?>">Dependent</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats7" value="0">
<td><input name="stats7" type="checkbox" id="emp" value="<?php echo $row["STAT7"]; ?>">Employee</td>
+1  A: 
<td></td>
<td><input name="stats6" type="checkbox" id="dep"  value="<?php echo $row["STAT6"]; ?>" <?php echo $row["STAT6"] ? 'checked="checked"' : ''; ?> >Dependent</td>
<td><font size="3"></td>
<td></td>
<td><input name="stats7" type="checkbox" id="emp" value="<?php echo $row["STAT7"]; ?>" <?php echo $row["STAT7"] ? 'checked="checked"' : ''; ?>>Employee</td>
solomongaby
+2  A: 

The easiest way to do this would be something like this:

<input name="stats6" type="checkbox" id="dep" <?php echo $row["STAT6"] ? "checked": ""; ?>>
Bas
A: 

You have to add the attribute "checked", if the box should be checked:

<td><input name="stats6" type="checkbox" id="dep"  value="<?php echo $row["STAT6"]; ?>" <? if($row["STAT6"]){ echo "checked"; } ?>>Dependent</td>

p2u