<?
   // Open database...
   include "config.inc";
   $db = @mysql_connect("localhost", "$databaseuser", "$databasepasswd");
   @mysql_select_db("$databasename",$db);

   // Check if affiliateID is in the database...
   $sql="SELECT affiliateid FROM affiliate WHERE affiliateid='$id'";
   $result = @mysql_query("$sql",$db);
   if (@mysql_num_rows($result) == 0) {
     header("Location: main.php");
     exit();
   } else {
     $sql="SELECT clicks FROM affiliatestats WHERE affiliateid='$id'";
     $result = @mysql_query("$sql",$db);
     $clicks = @mysql_result($result, 0, "clicks");
     $sql = "UPDATE affiliatestats SET clicks=$clicks+1 WHERE affiliateid='$id'";
     $result = @mysql_query("$sql",$db);
     setcookie("affiliate","$id", mktime(0,0,0,12,1,2020));
     header("Location: main.php");
   }
?>
