Jump to content

Mulktiple checkboxes, arrays


jwwceo

Recommended Posts

So I finally got my checkboxes working to where I can add them to a databse, and have the correct checkboxes already "checked" on the edit page when a user comes in the make changes...

however, what kind of query do I use to update any changes in the checkboxes...there might be as many as 50 boxes...

say theres 20 boxes currently checked and the user checks 10 more....an UPDATE query only updates current rows...in this case I'd need to update 20 and add 10....plus all the rows will have the same shirt_id since all the checkboxes relate to the same product....

does this make sense...
Link to comment
Share on other sites

Hi again..
What you could do is delete all rows already in DB then loop the array to insert all checked in


[code]mysql_query("DELETE * FROM tablename WHERE shirt_id = '$shirt_id'") or die (mysql_query());[/code]

that will dleete them all

then use

[code]foreach ($_POST['checkbox'] as $checkbox) {
mysql_query("INSERT INTO table_name (shirt_id, color) VALUES('$shirt_id','$color')") or die (mysql_query());
}[/code]

I based the code on you still talking about the shirts and colors site

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