Luke
Luke

Reputation: 527

Checkbox auto checked based on value from database

how can I auto check the checkbox based on the value from the database? I have the following code:

<input type="checkbox" name="CarModel" value="Yes"  ($row[CarModel]==Audi? 'checked' : '') >

Upvotes: 0

Views: 1618

Answers (1)

Raja
Raja

Reputation: 608

it should be like this

<input type="checkbox" name="CarModel" value="Yes"  <?php echo ($row['CarModel'] == 'Audi' ) ? 'checked' : NULL ; ?> >

Upvotes: 2

Related Questions