TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Fatal error: [] operator not supported for strings in /.... (http://www.talkphp.com/general/2900-fatal-error-operator-not-supported-strings.html)

pipesportugal 06-04-2008 11:57 PM

Fatal error: [] operator not supported for strings in /....
 
Hello there,

I started getting this message out of nothing.
Well, I've changed the hosting server for the website.

I already made many many tests and none of them sucessfull in order to solve this problem.

Can someone help, please?

This is the code:
===========================
include("include/dbconnect.php");
$query = "SELECT * FROM tabela_vendedores";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result))
{
$cod_vendedor[] = $row['cod_vendedor'];
$nome_vendedor[] = $row['nome_vendedor'];
}
===========================
pipesportugal

delayedinsanity 06-05-2008 12:32 AM

The problem seems to have something to do with PHP assuming you're assigning an array reference to a string - I don't know if this will work, but what if you tried initializing the two arrays before using them in the while loop?

PHP Code:

$cod_vendedor = array();
$nome_vendedor = array(); 

If just adding that doesn't work, maybe initialize them and then try this?

PHP Code:

while($row mysql_fetch_array($result))
{
array_push($cod_vendedor$row['cod_vendedor']);
array_push($nome_vendedor$row['nome_vendedor']);


Is your new host running a newer version of PHP than your old host was? The only reason [] shouldn't work is if it thinks you're trying to assign an array value to something that's already been set as a string, or if it's somehow causing duplicate key names, from what I gather.
-m

pipesportugal 06-05-2008 09:00 PM

Hi delayedinsanity,

I initialized the 2 arrays as per Your first suggestion and it solved the problem right away.

I guess that somehow I must have used this variables somewhere back (I did not go and check...) because there are a lot of includes and this subroutine was also an include itself.

I think the most important here is that the problem is solved.

I appreciated Your help. Thank You.
pipesportugal


All times are GMT. The time now is 09:03 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0