Jump to content

Checkboxes as an array or something?


Leader of Men

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/39364-checkboxes-as-an-array-or-something/
Share on other sites

<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 :-)

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.