PDA

View Full Version : Fetch Array Problems


soccer022483
09-01-2004, 03:05 PM
First off, here is the php code that created the table:
----------------------------------------------------
CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
`time` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;
----------------------------------------------------

I keep getting this error:
----------------------------------------------------
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site325/fst/var/www/html/shoutbox.php on line 58
----------------------------------------------------

Here is line 58:
----------------------------------------------------
while($r=mysql_fetch_array($result))
{stuff in here}
----------------------------------------------------

Here is the line right before (line 57)
----------------------------------------------------
$result = mysql_query("select * from shoutbox order by id desc limit 5");
----------------------------------------------------

Can someone tell me why I keep getting this error? The shoubox worked fine when I tested it locally using apache, but when I upload it to my domain it give me the error. Much thanks :)

Austin

trib4lmaniac
09-01-2004, 05:51 PM
You could try making the SQL keywords uppercase. I didn't think that this usually mattered to much but you never know.

<edit>
btw, that makes it
SELECT * FROM `shoutbox` ORDER BY `id` DESC LIMIT 5
Also put backticks in the correct places, that solved a problem for me once.
</edit>

raf
09-01-2004, 06:51 PM
are you sure there are records returned? The most common reason for this error is an empty recordset.

i don't think 'shoutbox' and 'id' are reserved words in MySQL so you don't need backticks. Besides, the error is on the next line .

LynxGrr
09-15-2004, 01:36 PM
The error could lie as far back as the connection to mysql.

You say it works locally but not on your server, so check to see if your hosting company set a username and password for your database.