Correct handling _POST[] and implode. PHP5

Correct handling _POST[] and implode. PHP5

am 09.10.2009 07:44:59 von bearsfoot

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

RE: Correct handling _POST[] and implode. PHP5

am 09.10.2009 09:13:28 von Andrea Giammarchi

--_bf4d78d2-c2ce-460f-afb1-ff341590a8a9_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable



>=20
> echo $_POST['Colors'] . '
'=3B // outputs 'Array'

try with

echo '

'=2C var_dump($_POST['Colors'])=2C '
'=3B

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=

--_bf4d78d2-c2ce-460f-afb1-ff341590a8a9_--

Re: Correct handling _POST[] and implode. PHP5

am 09.10.2009 09:43:16 von Gaurav Kumar

--001636e0a5ab9f506904757bbb6b
Content-Type: text/plain; charset=ISO-8859-1

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

--001636e0a5ab9f506904757bbb6b--

RE: Correct handling _POST[] and implode. PHP5

am 09.10.2009 10:14:20 von Andrea Giammarchi

--_d0abe5d9-8713-4a6d-835f-a09ce69cae8e_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



> 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=

--_d0abe5d9-8713-4a6d-835f-a09ce69cae8e_--

RE: Correct handling _POST[] and implode. PHP5

am 09.10.2009 10:17:51 von Andrea Giammarchi

--_36510fc9-f78c-41ca-9575-73dcd502ff5c_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



> 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 ...

if(isset($_POST['Colors']))
echo implode('=2C'=2C $_POST['Colors'])
=3B
?>


hecked" /> Green
Yellow
Red
Gray



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.

Thanks.



Andrea Giammarchi-3 wrote:
>=20
>=20
>=20
>>=20
>> echo $_POST['Colors'] . '
'; // outputs 'Array'
>=20
> try with
>=20
> echo '
', var_dump($_POST['Colors']), '
';
>=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'])
> ;
> ?>
>


> > /> Green
> Yellow
> Red
> Gray
>
>

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

RE: Correct handling _POST[] and implode. PHP5

am 09.10.2009 11:32:47 von Andrea Giammarchi

--_e140be0a-b453-418b-8a6a-fc23fb3afd7c_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable




> 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=

--_e140be0a-b453-418b-8a6a-fc23fb3afd7c_--