Page 1 of 1

SQL query syntax

Posted: Thu Mar 17, 2011 1:27 pm
by miramichiphoto
Can anyone see an error in my query syntax that would produce the following error?

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /mnt/.....edit_schedule.php on line 67

This is the code:

Code: Select all

$query = "SELECT * FROM `games` WHERE
`display_name`='".$_SESSION['display_name']."';";
               $result = mysql_query($query, $connection);
               $num=mysql_numrows($result); // <----THIS IS LINE 67
               $i=0;

               while ($i < $num){
$row = mysql_fetch_array($result); 
// table formed below
I have tried other syntax variations for the query, and get string errors, etc. The session variable echos ok.

Re: SQL query syntax

Posted: Thu Mar 17, 2011 1:59 pm
by anantha
it is mysql_num_rows if u r using mysql....

Re: SQL query syntax

Posted: Thu Mar 17, 2011 2:01 pm
by danwguy
get rid of your extra ; in the sql statement, the one that's inside your quotes.

Re: SQL query syntax

Posted: Thu Mar 17, 2011 2:08 pm
by divedj
Try the following:

Code: Select all

$query = "SELECT * FROM `games` WHERE
             `display_name`='".$_SESSION['display_name']."'"; //took the semikolon out after your display name var
               $result = mysql_query($query, $connection);
               $num=mysql_num_rows($result); // <----THIS IS LINE 67
The syntax mysql_numrows($res) is supposed to work. However I have had some cases it didn't. The proper syntax is mysql_num_rows($res);

Further check if the session display_name is set and is not only containing an empty string which as well would produse the described error.