Jump to content

array problem


Gaia

Recommended Posts

Hi,

I have a form that is submitting multiple checkboxes, which when submitted turns into an array.

So my $_POST['option'] turns into a foreach.

[code]
<?php

$options = $_POST['option'];

foreach ( $options AS $foo ) {

        $new_options .= 'Something: '.$foo.' &nbsp;';
}

?>
[/code]

The probem is when i submit it to a database the word Array gets stuck to the first option. so say the $options resulted in 3 check boxes being marked, option1, option2, and option3.

The output would be...

ArraySometing: option1 Something: option2 Something: option3

How do i fix that?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/9017-array-problem/
Share on other sites

$options is an array?


Do something like:
[code]
<?php

// do a loop on this, most likely...
$options[0] = $_POST['option1'];
$options[1] = $_POST['option2'];


// get the values and store as a string.
foreach ( $options AS $key=>$value )
{
        $new_options .= 'Something: '.$value.' &nbsp;';
}

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/9017-array-problem/#findComment-33157
Share on other sites

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.