Page 1 of 1

mysql fetch error?

Posted: Tue Apr 20, 2004 1:48 pm
by mike08
Trying to view a guestbook but i keep getting this error which i am struggling to overcome hope you can help. The error is

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\htdocs\shopbots\view_guest.php on line 13

Code: Select all

<?
//Display the top of the page for the guestbook
echo " <center><h1> Guestbook </h1></center><br>";
echo ' <a href="sign_guestbook.php"> Click here to leave us a message</a><br><br>';
echo " <b>comments from visitors </b><hr>";

//make the query
$query = "SELECT (username,email,comments) FROM users guestbook ORDER_BY user_id";
$result = @mysql_query ($query); //Run the query.

//Fetch and print all the records.
	while ($row = mysql_fetch_array($result)) 
	{
			echo "<b>username:</b> $row[0]<br>email: </b>$row[1]<br>
			<b>Comments:</b> $row[2]";	
	}
	    mysql_close(); // close the database connection
	?>

Posted: Tue Apr 20, 2004 1:52 pm
by magicrobotmonkey
try changing this line

Code: Select all

<?php
$result = @mysql_query ($query);
?>
with this

Code: Select all

<?php
$result = mysql_query ($query) or die("ERROR, ERROR!".mysql_error());
?>
and see what error you get

Posted: Tue Apr 20, 2004 2:00 pm
by mike08
i get this error - i did solve another error as i had users and guestbook in before but taken users out which was wrong but i now get this error

Code: Select all

ERROR, ERROR!You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'email,comments) FROM guestbook ORDER_BY user_id' at line 1

Posted: Tue Apr 20, 2004 2:04 pm
by magicrobotmonkey
you don't nee parentheses ( "()" ) around the username, email, comments in your query

Posted: Tue Apr 20, 2004 2:11 pm
by mike08
still doesn't seem to be working this is my code now

Code: Select all

$query = "SELECT username, email, comments FROM guestbook ORDER_BY user_id";
This is the error
ERROR, ERROR!You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'user_id' at line 1

Posted: Tue Apr 20, 2004 2:13 pm
by magicrobotmonkey
you have both a username and a user_id in your database? If so, I think you made need to select user_id as well in order to order by it

Posted: Tue Apr 20, 2004 2:30 pm
by mike08
unfortunately im still getting the same error - very confusing.

:?

Posted: Tue Apr 20, 2004 4:18 pm
by Deemo
it should be ORDER BY not ORDER_BY

Posted: Tue Apr 20, 2004 5:06 pm
by mike08
Thanks - works now :D