Jump to content

Archived

This topic is now archived and is closed to further replies.

Gaia

array problem

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
[code]

foreach($options as $array)
{
  foreach($array as $value)
  {
    echo $value;
  }
}

[/code]

Share this post


Link to post
Share on other sites

×

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.