Page 1 of 1

Visitor stats

Posted: Wed Oct 01, 2003 2:44 pm
by therat
I want to record the refering site to a db to see where people are coming from. I am using this to find the referer

Code: Select all

<?php
$refer   = $_SERVER['HTTP_REFERER'] ;
?>
and this to store the info to the database, which works as expected.

Code: Select all

<?php
if ( !isset($refer) == true) {$refer = 'Bookmark or Other'; }

$refer = "INSERT INTO stats_referer(referer) VALUES ('$refer')";

$result = mysql_query($refer, $skinz);
?>
This will currently create a new line in the database even if the referer already exists. How do I alter this to update a column called hits if the referer already exists in the database

Posted: Wed Oct 01, 2003 3:17 pm
by volka
first try to update the row with a hits=hits+1 statement
if this affects no row, insert a new one with an initial value of 1 for hits.
You might have to lock the table
or make the referer field unique and test wether INSERT was successful (if not update again)

see also:
http://www.mysql.com/doc/en/UPDATE.html
http://php.net/mysql_affected_rows


p.s.
what you're trying to do is exactly why my browser does not send any referer information to another site ;)

Posted: Wed Oct 01, 2003 3:43 pm
by therat
Thanks for the links. Ill give those a try