My Boss wants me to track all of the pages that users go to (we're a marketing company). It works fine, except for one problem : each time a user views a page, mySQL inserts TWO records instead of just one! Here is the code for the "track.php"
include (note: doconnect() is how I connect to mySQL)
function track($uid, $loc) {
$t = doconnect();
$findpage = "SELECT * from page where page.page = '$loc'";
$result = mysql_query($findpage,$t);
$row = mysql_fetch_array($result);
$num = mysql_num_rows($result);
// the page isn't indexed yet
if (!$num) {
$add = "INSERT INTO page VALUES ('','$loc');";
mysql_query($add);
$findpage = "SELECT * from page where page.page = '$loc'";
$result = mysql_query($findpage,$t);
$row = mysql_fetch_array($result);
}
$page_id = $row['page_id'];
$add = "INSERT INTO tracking VALUES ('',$uid,$page_id);";
mysql_query($add);
mysql_close($t);
}
Am I missing something? When I use it on a test page, the query only executes once. But when I put it on my "index.php" there are two records inserted for each page view.
Help!!!
THanks in advance.