<?php
include("config.php");

mysql_connect("$host", "$username", "$password")or die("cannot connect to the database."); 
mysql_select_db("$db_name")or die("cannot select the database.");

$url = $_SERVER['HTTP_REFERER'];
$parse = parse_url($url);
$referer = $parse['host'];

if ($referer == "") {
	//echo "no referer";
} else {
	$result = mysql_query("SELECT * FROM ".$prefix."websites WHERE website_domain = '".$referer."' ORDER BY id") or die("A MySQL error has 	occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());
	while($row = mysql_fetch_array($result)) {
		$website_url = $row['website_url'];
		$id = $row['id'];

		$sql = "UPDATE ".$prefix."websites SET hits_in_total=hits_in_total+1 WHERE id=".$id; 
		if (!mysql_query($sql)) {
			die('Error: ' . mysql_error());
		}

		$sql = "UPDATE ".$prefix."websites SET hits_in=hits_in+1 WHERE id=".$id; 
		if (!mysql_query($sql)) {
			die('Error: ' . mysql_error());
		}
	}
}
?>
