Re: Correct handling _POST[] and implode. PHP5
| From: | Gaurav Kumar | Date: | Fri, 09 Oct 2009 07:43:16 +0000 |
| Subject: | Re: Correct handling _POST[] and implode. PHP5 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298791@lists.php.net to get a copy of this message | ||
Its Simple...
Its very obvious that $_POST["color"] is not an array.
do something like this and you wil get the values.
$arr_color = $_POST["colors"];
//iterate over the array
foreach($arr_color as $val)
{
$str_color .= ", " . $val;
}
You are done.
Gaurav Kumar
Teach Lead Open Source Technologies
On Fri, Oct 9, 2009 at 11:14 AM, bearsfoot <adam.p.reynolds@gmail.com>wrote:
>
> Hi all,
>
> I have a form that has has an array of information. Mulitple checkboxes
> can
> be selected.
>
> Choose the colors:
> <input type="checkbox" name="Colors[]" value="green"
> checked="checked" />
> Green
> <input type="checkbox" name="Colors[]" value="yellow" />
> Yellow
> <input type="checkbox" name="Colors[]" value="red" /> Red
> <input type="checkbox" name="Colors[]" value="gray" /> Gray
>
> When processing the form..
>
> echo $_POST['Colors'] . '<br />'; // outputs 'Array'
>
> if ( isset($_POST['Colors']) ) {
> $_POST['Colors'] = implode(', ', $_POST['Colors']);
> //Converts an array
> into a single string
> }
>
> echo "Colors you chose: {$_POST['Colors']}<br />";
>
> I get the following error when using the implode function.
>
> Warning: implode() [function.implode]: Bad arguments
>
> What I doing wrong ?
>
> Thanks in advance.
>
>
>
> --
> View this message in context:
>
> http://www.nabble.com/Correct-handling-_POST---and-implode.-PHP5-tp25815789p25815789.html
> Sent from the PHP - General mailing list archive at Nabble.com.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>