petenaylor Posted July 19, 2012 Share Posted July 19, 2012 Hi all I am trying to write a piece of code that grabs post values. The form looks like this: Menus <input name="tagid" value="1" type="hidden" /> <input name="portfolioid" value="8" type="hidden" /> <input name="check_1" type="checkbox" value="1" /> Basically there will be a variable number of tick boxes. I need to grab the values that have the checkbox value of 1 and insert them into a mySQL database. I am already grabbing some other data from the form. How do I assign the input_name to a string in a loop? Many thanks Pete Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 19, 2012 Share Posted July 19, 2012 its not clear what you want to archieve here but can you atleast post you code and let as see what you were trying to archive? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 19, 2012 Share Posted July 19, 2012 I would Do this: Menus <input name="tagid" value="1" type="hidden" /> <input name="portfolioids[]" type="checkbox" value="8" /> And I believe a non checked box won't even pass in the $_POST, so you'll have an array called $_POST['portfolioids'] that contains all the values you checked. Then use an insert statement. There are many posts on here with examples of multiple inserts in one statement. Quote Link to comment Share on other sites More sharing options...
petenaylor Posted July 19, 2012 Author Share Posted July 19, 2012 Thanks for your help. I have now done print_r($_POST['portfolioids']); Which gives me : Array ( [19] => 8 [7] => 8 [8] => 8 [18] => 8 [20] => 8 [14] => 8 [9] => 8 [11] => 8 ) as I only ticked these boxes. I now need to write a loop to add these into my mySQL database. Can I do a for each on just these post values? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 19, 2012 Share Posted July 19, 2012 Well don't put 8 in each of them, put the ID in each one. Quote Link to comment 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.