Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

weird error in php/mysql

Status
Not open for further replies.

steijssen

Programmer
Mar 25, 2001
92
BE
Hello there,

I've been working with PHP/mySQL for a while, and as of today I get an error on the following query:

$query = "SELECT * FROM stats WHERE URL='$URL'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
//statements here
}

The error I get is "Warning: Supplied argument is not a valid MySQL result resource in d:\web\websites\phpincludes\visitor_stats.inc.php on line x"

Now I know this is because the resultset doesn't contain any rows, but normally it did't give this error on the fetch command, that is, until now.
Any ideas?

Thanks in advance,
Stijn Teijssen
 
Actually, this error occurs for many reasons, one of which is an invalid database connection (or one that does not exist).

First, check to make sure that the query being executed is being executed via a good database connection resource. After you have verified that, in your mysql_query() do:

$result = @mysql_query($query) or die(mysql_error().'IN FILE: '.__FILE__.'<br>ON LINE: '.__LINE__);

This might give you more insight as to where the problem lies.

NOTE: you should use or die() to handle errors in every possible location for debug purposes (such as in your mysql_pconnect() or mysql_connect() or mysql_select_db() calls).

Chad. ICQ: 54380631
online.dll
 
I had a quite similar problem a few weeks ago. You could try to exchange the &quot;=&quot; in your query string with a &quot;LIKE&quot;. Else you maybe have a lousy typo in your database connection. Who knows. Good luck:)

</imagetag>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top