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
mikusan
Forum Contributor
Posts: 247 Joined: Thu May 01, 2003 1:48 pm
Post
by mikusan » Thu Jul 24, 2003 8:11 am
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
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Thu Jul 24, 2003 9:23 am
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.
mikusan
Forum Contributor
Posts: 247 Joined: Thu May 01, 2003 1:48 pm
Post
by mikusan » Thu Jul 24, 2003 9:42 am
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?
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Thu Jul 24, 2003 10:00 am
Code: Select all
if ($SQL = mysql_query($query))
{
//do stuff
}
you would then need to add:
mikusan
Forum Contributor
Posts: 247 Joined: Thu May 01, 2003 1:48 pm
Post
by mikusan » Thu Jul 24, 2003 6:58 pm
I don't follow you sorry...
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Mon Jul 28, 2003 5:40 am
post your code that you are currently using.