Re: [PHP] Correct handling _POST[] and implode. PHP5

2009-10-09 Thread Gaurav Kumar
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.reyno...@gmail.comwrote:


 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




RE: [PHP] Correct handling _POST[] and implode. PHP5

2009-10-09 Thread Andrea Giammarchi


 
 echo $_POST['Colors'] . 'br /'; // outputs 'Array'

try with

echo 'pre', var_dump($_POST['Colors']), '/pre';

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

2009-10-09 Thread Andrea Giammarchi


 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

2009-10-09 Thread Andrea Giammarchi


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

?php
if(isset($_POST['Colors']))
echo implode(',', $_POST['Colors'])
;
?
form method=POST action=?
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
input type=submit /
/form

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

2009-10-09 Thread bearsfoot

Hi Andrea,

Thanks for your responses.

The output  from echo 'pre', var_dump($_POST['Colors']), '/pre';

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'] . 'br /'; // outputs 'Array'
 
 try with
 
 echo 'pre', var_dump($_POST['Colors']), '/pre';
 
 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

2009-10-09 Thread 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 ...
 
 ?php
 if(isset($_POST['Colors']))
 echo implode(',', $_POST['Colors'])
 ;
 ?
 form method=POST action=?
 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
 input type=submit /
 /form
 
 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

2009-10-09 Thread Andrea Giammarchi



 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

[PHP] Correct handling _POST[] and implode. PHP5

2009-10-08 Thread bearsfoot

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