PDA

View Full Version : PHP - MySQL referral counter not working



Cheap Bastard
July 19th, 2001, 02:13
Table:
(year month)
| simply splits the two fields of the table.

YYYYMM | 0
refcnt | ref_url
refcntref2 | ref_url2


somehow all i get is 1 referral URL with a count of 1. The YYYYMM | 0 stays there unharmed. The YYYYMM is simply there to know when to reset it.

Here's the referral part...


$month = date(Ym);
$sql = "SELECT refcnt FROM track0ref WHERE ref = \"0\"";
$result = @mysql_query("$sql",$dbconn);
$rowref = mysql_fetch_array($result);
$refmonth = $rowref['refcnt'];
if($refmonth == $month)
{
$sql = "SELECT refcnt FROM track0ref WHERE ref = \"$HTTP_REFERER\"";
$result = @mysql_query("$sql",$dbconn);
$rowref = mysql_fetch_array($result);
$refcnt = $rowref['refcnt'];
if($refcnt) {
$refcnt++;
$sql = "UPDATE track0ref SET refcnt = \"$refcnt\" WHERE ref = \"$HTTP_REFERER\"";
$result = @mysql_query($sql,$dbconn) or die("Couldn't update ref count");
} else {
$sql = "INSERT INTO track0ref (ref,refcnt) VALUES (\"$HTTP_REFERER\",\"1\")";
$result = @mysql_query($sql,$dbconn) or die("Couldn't insert ref values");
}


any clues? Probly a logical error :(

lucifer
July 19th, 2001, 07:47
where does it go wrong?

get it to echo all the variables as it goes along so you can see if they are what they should be

I always use ' rather than \" to make it clearer to see - but that's just me


....WHERE ref = \"0\" ... is ref a text/char field in your table?

Cheap Bastard
July 19th, 2001, 14:02
Originally posted by lucifer
where does it go wrong?

get it to echo all the variables as it goes along so you can see if they are what they should be

I always use ' rather than \" to make it clearer to see - but that's just me


....WHERE ref = \"0\" ... is ref a text/char field in your table?
from install.php :


$creation = "CREATE TABLE track0ref (ref TINYTEXT,refcnt INT)";
@mysql_query($creation,$dbconn) or die("Couldn't create database table track0ip");

$month = date(Ym);
$sql = "INSERT INTO track0ref (ref,refcnt) VALUES (\"0\",\"$month\")";
$result = @mysql_query($sql,$dbconn) or die("Couldn't insert values");

and should i make it echo the variables in the log or in the tracker itself?

lucifer
July 19th, 2001, 14:05
just to the page

$month = date(Ym);
echo $mounth;
$sql = "SELECT refcnt FROM track0ref WHERE ref = \"0\"";
$result = @mysql_query("$sql",$dbconn);
$rowref = mysql_fetch_array($result);
$refmonth = $rowref['refcnt'];
echo $refmonth;

type thing

if (...) { echo "got this far";

just so you track where things are