Julian Posted June 8, 2009 Share Posted June 8, 2009 Hello guys. I've been looking around and I did not find a solution for my current situation. Here's my question, I want to insert a new record for each checkbox that had been checked on a specific table. (`profile`) Checkboxes are created dynamically from another table (`categories`). Here's code example: mysql_query("INSERT INTO profile (user_id, user_category) VALUES ($user_id, $(checked boxes); //Checked boxes <?php while ($row_cat = mysql_fetch_assoc($cat)) { echo '<td><input name="user_category" type="checkbox" id="user_category" value="1" /></td>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/161370-insert-checkboxes-data/ Share on other sites More sharing options...
Adam Posted June 8, 2009 Share Posted June 8, 2009 Here's my question, I want to insert a new record for each checkbox that had been checked on a specific table. (`profile`) Checkboxes are created dynamically from another table (`categories`). That's not a question... Quote Link to comment https://forums.phpfreaks.com/topic/161370-insert-checkboxes-data/#findComment-851536 Share on other sites More sharing options...
jxrd Posted June 8, 2009 Share Posted June 8, 2009 If you name them all user_category[] then they will be put into an array. So you can do foreach($_POST['user_category'] as $key => $value) { //insert...do whatever etc. } And yeah lol nice observation MrAdam. Quote Link to comment https://forums.phpfreaks.com/topic/161370-insert-checkboxes-data/#findComment-851537 Share on other sites More sharing options...
Julian Posted June 8, 2009 Author Share Posted June 8, 2009 Here's my question, I want to insert a new record for each checkbox that had been checked on a specific table. (`profile`) Checkboxes are created dynamically from another table (`categories`). That's not a question... You're not helping sir. Thanks jxrd for the help.. Can you `code` explain it. How to break the array in order to insert each one as a new record... Regards Quote Link to comment https://forums.phpfreaks.com/topic/161370-insert-checkboxes-data/#findComment-851553 Share on other sites More sharing options...
jxrd Posted June 8, 2009 Share Posted June 8, 2009 You put your insert query into that foreach loop, and refer to the posted data as $value. Quote Link to comment https://forums.phpfreaks.com/topic/161370-insert-checkboxes-data/#findComment-851563 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.