Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jaerdin

PHP error

This topic is 5273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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 )


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!