Php – how to make a checkbox selected

htmlPHP

In my application's CMS, I have an edit items form.

The items users will be editing have some checkboxes.

Some of them were selected upon creation, and that selection has been stored in my database, because it affects how items are displayed in the actual site.

Supposing $checked is a boolean variable that is true if the user that created the item had selected the box, what would be my code to show a selected checkbox if($checked) ?

Best Answer

echo '<input type="checkbox" value="123" '.($checkedValue == 123 ? 'checked="checked"':'').' />';