Jump to content

Checkbox checked with database value


vinpkl

Recommended Posts

hi all

 

I have 3 checkboxes whose values are getting stored in the database with a comma separator.

 

<input name="color[]" type="checkbox" value="red" id="red" />red  
<input name="color[]" type="checkbox" value="blue" id="blue" />blue 
<input name="color[]" type="checkbox" value="green" id="green" />green

 

values getting stored with comma separator

 

red, blue, green

 

now i want to show the checkboxes as "checked" to show the customer as which colors they chose lasttime when they submitted the form.

 

How can i make it possible ?

 

If it is possible without the comma separator then i can remove the comma.

 

vineet

Link to comment
Share on other sites

Ideally you would store each form field separately.

 

The code you are looking for is something like

 

Inside your record set while

if($row['red'] == 1){
        echo "<input type="chcekbox" checked"/>";
} else {
        echo "<input type="chcekbox""/>";
}

 

So if the field is set in the recordset the checkbox will display correctly.

 

Tadaa

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.