1

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>

3 Answers 3

3
<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>
Sign up to request clarification or add additional context in comments.

Comments

2

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

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

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.