Leader of Men Posted February 20, 2007 Share Posted February 20, 2007 So I have a form and I am bringing this form into mysql via php. Basically, I want to the checkboxes to all have the same name, let's call it content_key because that is what it is called. So if all these have the name content_key and different values, but when they send the output, they send the last value selected only. I want it to send them all, maybe as an array or something. So that I can run a for each statement through the array when bringing the information back in. Any way to do this? Otherwise I'll just have them all having different names and a value of yes. Quote Link to comment https://forums.phpfreaks.com/topic/39364-checkboxes-as-an-array-or-something/ Share on other sites More sharing options...
fenway Posted February 21, 2007 Share Posted February 21, 2007 You get a collection in your POST data... don't know how you're retrieving it. I've seen people use fieldName[] because apparently that's magical to php...? Quote Link to comment https://forums.phpfreaks.com/topic/39364-checkboxes-as-an-array-or-something/#findComment-190231 Share on other sites More sharing options...
lando Posted February 21, 2007 Share Posted February 21, 2007 Fenway is correct. You will end up with something similiar: $_POST['content_key'][0], $_POST['content_key'][1], $_POST['content_key'][2], $_POST['content_key'][3], $_POST['content_key'][4] Quote Link to comment https://forums.phpfreaks.com/topic/39364-checkboxes-as-an-array-or-something/#findComment-190472 Share on other sites More sharing options...
janroald Posted February 23, 2007 Share Posted February 23, 2007 <input type="checkbox" name="borat[]" value="crazy"><br> <input type="checkbox" name="borat[]" value="little"><br> <input type="checkbox" name="borat[]" value="khazhakstan-man"><br> We send the form... <? echo '<pre>'; print_r($_POST[borat]); echo '</pre>'; ?> Then we get the output : Array ( [0] => crazy [1] => little [2] => khazhakstan-man ) Try it, play with it and use it a lot from now on :-) Quote Link to comment https://forums.phpfreaks.com/topic/39364-checkboxes-as-an-array-or-something/#findComment-192485 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.