chronister Posted July 21, 2007 Share Posted July 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/61054-solved-please-explain-why-this-error-is-coming-up/ Share on other sites More sharing options...
MadTechie Posted July 21, 2007 Share Posted July 21, 2007 try $date[]=$row['d']; $question[]=$row['question']; // line 13 $answer[]=$row['answer']; // line 14 Link to comment https://forums.phpfreaks.com/topic/61054-solved-please-explain-why-this-error-is-coming-up/#findComment-303847 Share on other sites More sharing options...
chronister Posted July 21, 2007 Author Share Posted July 21, 2007 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? Link to comment https://forums.phpfreaks.com/topic/61054-solved-please-explain-why-this-error-is-coming-up/#findComment-303850 Share on other sites More sharing options...
hvle Posted July 21, 2007 Share Posted July 21, 2007 This maybe because $date was not declare first. try to declare $date as an array before using it: $date = array(); Link to comment https://forums.phpfreaks.com/topic/61054-solved-please-explain-why-this-error-is-coming-up/#findComment-303852 Share on other sites More sharing options...
AndyB Posted July 21, 2007 Share Posted July 21, 2007 Are $date, $question, or $answer used as string variables previously in your code? Link to comment https://forums.phpfreaks.com/topic/61054-solved-please-explain-why-this-error-is-coming-up/#findComment-303855 Share on other sites More sharing options...
chronister Posted July 21, 2007 Author Share Posted July 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/61054-solved-please-explain-why-this-error-is-coming-up/#findComment-303886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.