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.

Link to comment
Share on other sites

 <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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.