Page 1 of 1

Problems with arrays

Posted: Fri Jun 03, 2005 9:28 pm
by nyl
I have this code

Code: Select all

$_SESSION['productid'][] = $temp_productid ;
When I load the page the first time it works.
After that it gives me this error:

Code: Select all

Fatal error: [] operator not supported for strings....
It works fine on my machine locally. when I upolad
the file to the server it gives me this problem.

Someone said it happens when a string is assigned to an array that makes the problem. But it works on my computer.

Posted: Sat Jun 04, 2005 4:12 am
by anjanesh
Before the error line what does print_r($_SESSION) give ?

Re: Problems with arrays

Posted: Sat Jun 04, 2005 8:13 am
by neophyte
nyl wrote:I have this code

Code: Select all

$_SESSION['productid'][] = $temp_productid ;
When I load the page the first time it works.
After that it gives me this error:

Code: Select all

Fatal error: [] operator not supported for strings....
First always code with error_reporting(E_ALL); at the top of your page. This will give you consistant error reporting and more stable code. Then remove it when you done testing. I'd print $_SESSION array to the screen. If the problem persists I'd a assign a key to 'productid'.

Code: Select all

$_SESSION['productid']['some_num_or_name_val'] = $temp_productid;
If the idea is to have multiple product ids assigned to the value make them seperated with a "," or "|" and explode()/implode() the list as needed...

Hope this helps...