We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
SQL Query Troubleshoot!
Topic Started: Jun 12 2005, 11:28 AM (284 Views)
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
Code:
 

<?
$user = $_SESSION['user'];
$result = mysql_query("SELECT `grid_id` FROM `grid` WHERE `grid_owner` = `$user`");
$num_rows = mysql_num_rows($result);
echo $num_rows;
?>


Error:
Quote:
 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\php\www\horthonline\overview.php on line 4


I gather from my googling that the errors means line 3 is incorrect, rather than line 4 as that simply links to line 3. The problem is i can't find the fault in my syntax.

The $user variable and session thing is fine, but i keep getting the error. I am connected to mysql fine.

Thanks for the help by anybody who can respond!

Kingy
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
Try removing the little wierd looking single quote things (whatever they're called) from your SQL query and use normal single quotes around $user so your SQL query looks like this.
Code:
 
mysql_query("SELECT grid_id FROM grid WHERE grid_owner = '$user'");


You can also debug your SQL queries like this.
Code:
 
mysql_query("SELECT grid_id FROM grid WHERE grid_owner = '$user'") or die(mysql_error());


That way if the query is unsuccessful it will kill the script and print the SQL error.
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
Thankyou very much, the debug allowed me to see it was a problem elsewhere in my code affecting it.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply