RE: [PHP] Correct handling _POST[] and implode. PHP5
> Date: Fri, 9 Oct 2009 02:07:55 -0700 > From: adam.p.reyno...@gmail.com > To: php-general@lists.php.net > Subject: RE: [PHP] Correct handling _POST[] and implode. PHP5 > > > I just realised I have get_magic_quotes_gpc turned on and was not catering > for arrays. > that's why I asked about PHP version ... latest have magic_quotes and register_globals off by default and I strongly suggest to configure whatever server like that because there shouldn't be anything "magic" when we talk about security or programming. Regards _ Keep your friends updated—even when you’re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010
RE: [PHP] Correct handling _POST[] and implode. PHP5
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:WLMTAGL: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: [PHP] Correct handling _POST[] and implode. PHP5
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 ok ? That has me baffled. I am several forms within the application, but this is the first array. Thanks. Andrea Giammarchi-3 wrote: > > > >> >> echo $_POST['Colors'] . ''; // outputs 'Array' > > try with > > echo '', var_dump($_POST['Colors']), ''; > > to be sure abot the structure. Also, which PHP version? > > Regards > > _ > Keep your friends updated—even when you’re not signed in. > http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010 > -- 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: [PHP] Correct handling _POST[] and implode. PHP5
> 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 ... 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:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
RE: [PHP] Correct handling _POST[] and implode. PHP5
> 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; > } 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? _ Windows Live: Keep your friends up to date with what you do online. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010
RE: [PHP] Correct handling _POST[] and implode. PHP5
> > echo $_POST['Colors'] . ''; // outputs 'Array' try with echo '', var_dump($_POST['Colors']), ''; to be sure abot the structure. Also, which PHP version? Regards _ Keep your friends updated—even when you’re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010
Re: [PHP] Correct handling _POST[] and implode. PHP5
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 > >
[PHP] Correct handling _POST[] and implode. PHP5
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