Gettng checkbox values

I have a form that updates a table row. In the row are 9 checkboxes. I want to have the box checked in the update form if it is checked, or the value is 1 in the DB.


<input type="checkbox" name="realestate" id="realestate" 
value="<?php if ($row_WAATKlawfirm['realestate']=="1")  echo 'checked';?>" />

All of the db connections work, the results from the other fields show up as planned, cant seem to get the check boxes to show checked in the update field.

Another point, the checkbox in the db is set to a varchar(15)

Thanks for your help.

Gary

The attribute checked cannot be in the value attribute, the below should work.

<input type="checkbox" name="realestate" id="realestate" 
value="1"<?php if ($row_WAATKlawfirm['realestate']=="1") echo ' checked="checked"'; ?> />

Hi Gary,

You can store checkbox values as a boolean in mysql using tinyint instead of varchar. That way you can store 1 for true and 0 for false. I know its not directly related to your problem but I thought I’d mention it :wink:

@SgtLegend

Worked perfectly, thank you very much…

@tangoforce

I think the original plan was to input the text into the db col (check estate and ‘estate’ is now listed in the estate col). I might go in and change it but that is down the list of priorities at this point.

Thanks for checking in.

Gary