Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fatal error: [] operator not supported for strings

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
I guys :)

I'm totally clueless about the error I'm getting (Fatal error: [] operator not supported for strings ).

Look at the last line :

Code:
$query_result = mysql_query($query_string, $_db_connect) or die (hd_mysql_alert(mysql_error(), $query_string, $ext_lang));

$mysql_num = mysql_affected_rows();

		if(strstr($action, "SELECT")) {
		
    $i = 0;

		$mysql_num = mysql_num_rows($query_result);

		    // - ! - loop through colums/fields
		    while ($i < mysql_num_fields($query_result)) {
		    
		    $field_result_array[] = mysql_field_name($query_result, $i);
		    
		    $i++;
		    
		    }

		    // - ! - loop through rows
				while ($row = mysql_fetch_array($query_result)) {
		        
		        // - ! - loop through colums/fields
            foreach ($field_result_array as $field_name) {

                // - ! - if result gives one row
                if ($mysql_num == 1) {
                
                    // - ! - store into post
                    if ($template == "POST") {
                    
                    $_POST[$field_prefix . $field_name] = $row[$field_name];
                    
                    // - ! - store into global
                    } else {
                    
            				$GLOBALS[$field_prefix . $field_name] = $row[$field_name];
            				
            				}

                // - ! - if result gives more than one row
                } else if ($mysql_num > 1) {
                
                // !!!!!!! this line gives the error !!!!!!!!
                $GLOBALS[$field_prefix . $field_name][] = $row[$field_name]; 
                
                }
    				
    				}
        
        }

		}

Any idea?
 
Sleila,

It is no secret that I am a PHP rookie and so I will ask the question:

What are [] meant to do in the above? It appears that you are using them as operators ...

I think this calls for a trip to php.net :)

Regards,


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
Code:
$GLOBALS[$field_prefix . $field_name][red][][/red]


I think you have an extra set of square brackets [] there.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Vacunita :)

The extra set is the normal way to construct an array, so it shouldn't trigger an error.

What I discovered is that there is this error because, on other parts of the function, $GLOBALS[$field_prefix . $field_name] is a string, not an array.

But this is uncomprehensible because the type of this variable depends only on $mysql_num being equal to 1 or superior to 1. And, in this function, $mysql_num is either one or the other. It can't be both. So, $GLOBALS[$field_prefix . $field_name] is either only a string or only an array.

So, what's going on???


 

Ok, I solved the problem by changing this part :

Code:
...
// - ! - if result gives more than one row
} else if ($mysql_num > 1) {

    if (!is_array($GLOBALS[$field_prefix . $field_name])) $GLOBALS[$field_prefix . $field_name] = array(); // added this

$GLOBALS[$field_prefix . $field_name][] = $row[$field_name];

}
...

I still don't understand why it was necessary though :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top