SQL query syntax

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
miramichiphoto
Forum Newbie
Posts: 14
Joined: Thu Mar 17, 2011 1:12 pm

SQL query syntax

Post 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.
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: SQL query syntax

Post by anantha »

it is mysql_num_rows if u r using mysql....
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: SQL query syntax

Post by danwguy »

get rid of your extra ; in the sql statement, the one that's inside your quotes.
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Re: SQL query syntax

Post 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.
Post Reply