• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP - MySQL referral counter not working

Cheap Bastard

New Member
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...

PHP:
$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 :(
 
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?
 
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 :

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?
 
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
 
Back
Top