Jump to content

checkbox ticked if value exists in database


kapz22

Recommended Posts

Hi all, i am having issues with ticking a checkbox if that value exists in the database.

 

Basically i have a form containing about 20 check boxes. when you tick them, the value is inserted into the database and the page reloads. When the page relaods, i want the check boxes ticked, only if those value exists in the database.

i know that that "checked" has to be inserted inside the input parameters.

 

i have the follwing code:

 

<?php

while ($row = mysql_fetch_assoc($resul)) {

?>

<input type="checkbox" name="checkbox[]" value="<?php echo $row["id"]; ?>" <?php echo $checked; ?> />

<?php echo $row["name"]; ?><br />

<?php

}

?>

 

How do i get these boxes ticked, it the id exists in the database?

Please advise me on what i need to do.

 

Thanks.

 <input type="checkbox" name="checkbox[]" value="<?php echo $row["id"]; ?>" <?php echo ($row['checkbox_value'] == 1) ? "CHECKED='CHECKED'" : ''; ?> />

 

I'm sure what your set value is for these checkboxes but I usually use 1. Basically check the checkbox value against whatever your set value is (1 in this case).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.