Jump to content

[SOLVED] Please explain why this error is coming up..


chronister

Recommended Posts

Fatal error: [] operator not supported for strings in /path/to/files on line 13 (get the same for line 14)

 

 

Here is the code.

<?php

$query="SELECT question, answer, date as d FROM jotd, jokes WHERE jotd.jokeid = jokes.jokeid";
$result=mysql_query($query);
while($row=mysql_fetch_object($result))
{
$date[]=$row->d;
$question[]=$row->question; // line 13
$answer[]=$row->answer;  // line 14
}

?>

 

It don't bitch about the $date[] part which is a unix time stamp, but it don't like the question or answer for this joke archive script.

 

I have run into this before and just said F*$K it and moved on to a different way to accomplish it, but this time I would like to understand what the hell is going on here.

 

THanks for your help.

 

Nathan

 

same

 

new code

<?php 

$query="SELECT question, answer, date as d FROM jotd, jokes WHERE jotd.jokeid = jokes.jokeid";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
$date[]=$row['d'];
$question[]=$row['question'];
$answer[]=$row['answer'];
}

?>

 

The db data type is varchar(255), would that have anything to do with it?

Are $date, $question, or $answer used as string variables previously in your code?

 

That is the problem. I "forgot" that I was using $question  & $answer in my header file which is an included file. I changed them to $q & $a , and all is right with the world :)

 

Thanks, now I know what to look for if I run into this error again.

 

 

much obliged for the help folks.

 

Nate

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.