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
https://forums.phpfreaks.com/topic/18926-mulktiple-checkboxes-arrays/
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

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.