I have a form that has has an array of information. Mulitple checkboxes can
be selected.
Choose the colors:
Green
Yellow
Red
Gray
When processing the form..
echo $_POST['Colors'] . ' '; // outputs 'Array'
if ( isset($_POST['Colors']) ) {
$_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array
into a single string
}
echo "Colors you chose: {$_POST['Colors']} ";
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
to be sure abot the structure. Also=2C which PHP version?
Regards
=0A=
____________________________________________________________ _____=0A=
Keep your friends updated=97even when you=92re not signed in.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_5:092=
010=
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 wrote:
>
> Hi all,
>
> I have a form that has has an array of information. Mulitple checkboxes
> can
> be selected.
>
> Choose the colors:
>
> Green
> Yellow
> Red
> Gray
>
> When processing the form..
>
> echo $_POST['Colors'] . ' '; // outputs 'Array'
>
> if ( isset($_POST['Colors']) ) {
> $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array
> into a single string
> }
>
> echo "Colors you chose: {$_POST['Colors']} ";
>
> 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
>
>
> Its very obvious that $_POST["color"] is not an array.
>=20
> do something like this and you wil get the values.
>=20
> $arr_color =3D $_POST["colors"]=3B
>=20
> //iterate over the array
> foreach($arr_color as $val)
> {
> $str_color .=3D "=2C " . $val=3B
> }
so it's simple=2C it's not an array=2C but your assignment magically makes =
it an array since you wrote "iterate over the array" ... very=2C very clear=
=2C isn't it?
=0A=
____________________________________________________________ _____=0A=
Windows Live: Keep your friends up to date with what you do online.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_1:092=
010=
> so it's simple=2C it's not an array=2C but your assignment magically make=
s it an array since you wrote "iterate over the array" ... very=2C very cle=
ar=2C isn't it?
OK=2C sarcasm a part=2C this works perfectly for me=2C and it's quite obvio=
us Colors IS an array ...
Regards
=0A=
____________________________________________________________ _____=0A=
Windows Live: Friends get your Flickr=2C Yelp=2C and Digg updates when they=
e-mail you.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_3:092=
010=
--_36510fc9-f78c-41ca-9575-73dcd502ff5c_--
RE: Correct handling _POST[] and implode. PHP5
am 09.10.2009 10:59:56 von bearsfoot
Hi Andrea,
Thanks for your responses.
The output from echo '
', var_dump($_POST['Colors']), '
';
is --> string(5) "Array"
I am using php version 5.2.10.
It is strange that you posted the same array and ran the implode function o=
k
? That has me baffled. I am several forms within the application, but
this is the first array.
';
>=20
> to be sure abot the structure. Also, which PHP version?
>=20
> Regards
> =09 =20
> ____________________________________________________________ _____
> Keep your friends updatedâ=94even when youâ=99re not signed in.
> http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/=
social-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL: en-xm:SI_SB_5:0=
92010
>=20
--=20
View this message in context: http://www.nabble.com/Correct-handling-_POST-=
--and-implode.-PHP5-tp25815789p25817793.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
RE: Correct handling _POST[] and implode. PHP5
am 09.10.2009 11:07:55 von bearsfoot
I just realised I have get_magic_quotes_gpc turned on and was not catering
for arrays.
Thanks for your time.
Adam
Andrea Giammarchi-3 wrote:
>
>
>
>> so it's simple, it's not an array, but your assignment magically makes it
>> an array since you wrote "iterate over the array" ... very, very clear,
>> isn't it?
>
> OK, sarcasm a part, this works perfectly for me, and it's quite obvious
> Colors IS an array ...
>
>
> if(isset($_POST['Colors']))
> echo implode(',', $_POST['Colors'])
> ;
> ?>
>
>
> Regards
>
> ____________________________________________________________ _____
> Windows Live: Friends get your Flickr, Yelp, and Digg updates when they
> e-mail you.
> http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLM TAGL:ON:WL:en-xm:SI_SB_3:092010
>
--
View this message in context: http://www.nabble.com/Correct-handling-_POST---and-implode.- PHP5-tp25815789p25817889.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
> Date: Fri=2C 9 Oct 2009 02:07:55 -0700
> From: adam.p.reynolds@gmail.com
> To: php-general@lists.php.net
> Subject: RE: [PHP] Correct handling _POST[] and implode. PHP5
>=20
>=20
> I just realised I have get_magic_quotes_gpc turned on and was not caterin=
g
> for arrays.
>=20
that's why I asked about PHP version ... latest have magic_quotes and regis=
ter_globals off by default and I strongly suggest to configure whatever ser=
ver like that because there shouldn't be anything "magic" when we talk abo=
ut security or programming.
Regards
=0A=
____________________________________________________________ _____=0A=
Keep your friends updated=97even when you=92re not signed in.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_5:092=
010=