0

I have a page to view assets with an Edit link. When I click the link it goes to edit_case.php which has a form to edit what elements of the row are in the database as checkboxes. However the boxes do not show them as checked. I have the following code...

// get already checked box values 
$repop = "SELECT * FROM case_audit WHERE case_id = $case_id";
$popresults = mysqli_query($dbc, $repop);
$row = mysqli_fetch_array($popresults, MYSQLI_ASSOC);

print_r ($row);

The print_r does show the whole record row from DB. which is either a 1 or 0, checked || not checked.

The form...

<div id="facepics">
 <label><input type="checkbox" name="Facial1" value="<?php echo $row['frontrest']; ?>" >Front at Rest </label><br>
 <label><input type="checkbox" name="Facial2" value="<?php echo $row['frontbigsmile']; ?>" >Front Big Smille</label><br>
 <label><input type="checkbox" name="Facial3" value="<?php echo $row['profile']; ?>" >Profile</label><br>
 <label><input type="checkbox" name="Facial4" value="<?php echo $row['subvertex']; ?>" >SubMento Vertex</label><br>
</div>

I know I need to turn the 1's to "checked" just not sure how best to do that.

Steveep
  • 25
  • 6

2 Answers2

0

so basically checked="true" attribute in input creates a checked checkbox. HTML Code looks like

<input type="checkbox" checked="true">

In your case you can do it like:

<input type="checkbox" name="Facial1" value="frontrest" <?= (intval($row['frontrest']) == 1) ? 'checked' : '';>

Also note that I changed value attribute, with frontrest so that you can identify the checkbox uniquely

EDIT: I have modified the code

Minhaz
  • 937
  • 1
  • 10
  • 25
0

<input type="checkbox" name="Facial1" <?=$row['frontrest']==1?'checked':''?>>

I often have the same issue where the browser ignores checked="false" and checks all so I use

<input type="checkbox" checked>

Dug
  • 315
  • 5
  • 11