Skip to main content
gamedev.net
🔒 Locked

PHP error

Started by Jaerdin Jun 7, 2004 at 2:41 AM 7 replies 550+ views
Original Post
Jaerdin
Jaerdin
I keep getting an error when trying to access my php code... the error message is : Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /local/start.php on line 14 Line 14 is: $num=mysql_numrows($query); any ideas? thanx, Jaerdin
"A journey of a thousand miles begins with a single step" - Confucius
Direct4D
Direct4D
Where did that variable $query come from ?

It should come from a mysql_query eg:

$query = mysql_query("SELECT... blah blah blah ");

(for the SQL purists out there: blah is not valid SQL syntax... i just used it as placeholder for a valid SQL query )


BlindTechie
BlindTechie
As aforementioned, $query is invalid. No need to post the code preceding this line.

In order to debug your code easier try using something like this right after the query is made:

if (!$query)
{
die(''Query failed: ''.mysql_error());
}

If the query has an error, then $query will return false. This if statement determines if there is a nerror and reports it, then terminates the script if there is an error. I hope this helps.
Chip
Chip
Actually its not the query first off. The actual function is mysql_num_rows. However its not to wise to put the actual query in a function like that.

Try This:

$connection = mysql_connect( "$dbhost", "$dbuser", "$dbpass");
$query = mysql_query("QUERY GOES HERE");
$results = mysql_query($query, $connection) OR DIE ("Error in query: $query. " . mysql_error());

Then use:

$num = mysql_num_rows ( $results );

That works. Hope it helps ya.

Chip Lambert
President/Lead Programmer LambertSoft

[edited by - Chip on June 7, 2004 10:09:43 AM]
Chip LambertPresident/Lead Programmer LambertSoft
Kylotan
Kylotan
quote:
Original post by Chip
Try This:

$connection = mysql_connect( "$dbhost", "$dbuser", "$dbpass");
$query = mysql_query("QUERY GOES HERE");
$results = mysql_query($query, $connection) OR DIE ("Error in query: $query. " . mysql_error());


That''s quite bizarre and wrong. You wouldn''t pass the result of mysql_query to another mysql_query.



[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
Chip
Chip
Ooops my bad, I meant

$query = "QUERY GOES HERE";
$results = mysql_query($query, $connection) OR DIE ("Error in query: $query. " . mysql_error());

I apologize about that.
Chip LambertPresident/Lead Programmer LambertSoft
Jaerdin
Jaerdin
thanks for the help, this is what finally worked...

mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result=mysql_query("SELECT * FROM accounts WHERE username=''$loginid''");
$num=mysql_num_rows($result);
"A journey of a thousand miles begins with a single step" - Confucius

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.