KevinM1 Posted March 8, 2007 Share Posted March 8, 2007 This isn't so much a question on how to do it (which is simple), but rather if my desired method will work. Typically, checkbox inputs have a name value of an array (something like <input name="options[]" type="checkbox" />). Is there an easy way for me to extract the values of such an array and insert them into the right database column? Or should I just bite the bullet and give each checkbox input a unique name so I save myself some confusion/readability? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/41808-inserting-checkbox-data-into-a-database-a-question-of-method/ Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 foreach ($_POST['options'] as $opt) { mysql_query("INSERT INTO mytable (fk_ID, option) VALUES ('$id', '$opt')"); } or, if you haven't normalized your data and just want to throw them all into a single field $opts = join (', ', $_POST['options']); mysql_query("INSERT INTO mytable (option) VALUES ('$opts')"); Quote Link to comment https://forums.phpfreaks.com/topic/41808-inserting-checkbox-data-into-a-database-a-question-of-method/#findComment-202850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.