Page 1 of 1

Unespected SQL error

Posted: Thu Jul 24, 2003 8:11 am
by mikusan
Here is the code and the error i get...
Two things to keep in mind:
1 the code seemed to work for a while
2 it broke :)

Code: Select all

if (!empty($_SERVER['HTTP_REFERER']))
	{
		$SQL = "SELECT referrer,count FROM vc_referrer WHERE referrer='{$_SERVER['HTTP_REFERER']}'";
		if (mysql_query($SQL))	{

			$Data = mysql_fetch_array($SQL);
			$count = $Data['count'] + 1;
			mysql_query("UPDATE vc_referrer SET count='$count' WHERE referrer='{$_SERVER['HTTP_REFERER']}'");

		}
		else	{

		mysql_query("INSERT INTO vc_referrer ( referrer ) VALUES ( '{$_SERVER['HTTP_REFERER']}' )");

		}
	}
The error i get:
Evil SQL error wrote: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/index.vc on line 31
Line 31 is the "$Data = mysql_fetch_array($SQL);
" line...

thanks

Posted: Thu Jul 24, 2003 9:23 am
by nielsene
I'm not a MySQL'r, but I would expect you to need to do something like (please note function names/argument counts might be a little off)

Code: Select all

$SQL =....
$result= mysql_query($SQL);
if (mysql_numrows($result))
{
 ...
  $data = mysql_fetch_assoc($result);
...
It looks like your are confusing the string containing the textual query and the resource pointer to a database result.

Posted: Thu Jul 24, 2003 9:42 am
by mikusan
Yes that indeed was the problem... i think what i wanted to do was this but somewhere along the lines i altered my line of thought

Code: Select all

if ($SQL = mysql_query($query))
{
//do stuff
}
<b>EDIT</B>
Nope after a while that gave me a similar error:
Evil Evil SQL error wrote: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in
What's up with this?

Posted: Thu Jul 24, 2003 10:00 am
by Wayne

Code: Select all

if ($SQL = mysql_query($query)) 
&#123; 
//do stuff 
&#125;
you would then need to add:

Code: Select all

mysql_num_rows($SQL);

Posted: Thu Jul 24, 2003 6:58 pm
by mikusan
I don't follow you sorry...

Posted: Mon Jul 28, 2003 5:40 am
by Wayne
post your code that you are currently using.