i have a table set up with information on banners used on my site, the actual images are only referred to by path in the database, and using a redirect page i am trying to 'log' how many time the banner is clicked through.
first a random banner is picked on any one of the pages using the code:
<?
$db_name = "nonothingrockdb";
$table_name = "banner_ads";
$connection = @mysql_connect("localhost", "user", "pass")
or die("Couldn't connect.");
$db = mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$now = date("Y-m-d");
$sql = "SELECT bannerID, banner_file, active, date_renew
FROM $table_name
WHERE active = 1 AND date_renew >= \"$now\"
ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
while($row = mysql_fetch_array($result)) {
$banner_file = $row['banner_file'];
$ad_url = $row['ad_url'];
$bannerID = $row['bannerID'];
$image = "http://www.no-nothingrock.com/ads/files/$banner_file";
$display_ad = "<A HREF=\"adclick.php?bannerID=$bannerID\" TARGET=\"_top\">
<IMG SRC=\"$image\" BORDER=0></A>";
}
?>
such as: http://www.no-nothingrock.com/noise/
outputs only one, random, banner and link. and the link is the redirect code... where it processes the information sent via bannerID and then updates the database for that banner to add 1 to the previous 'hits' on the banner.
the code:
<?
$db_name = "nonothingrockdb";
$table_name = "banner_ads";
$connection = @mysql_connect("localhost", "user", "pass")
or die("Couldn't connect.");
$db = mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = "SELECT ad_url, hits, bannerID
FROM $table_name
WHERE bannerID = \"$bannerID\" ";
$result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
while($row = mysql_fetch_array($result)) {
$hits = $row['hits'];
$ad_url = $row['ad_url'];
$bannerID = $row['bannerID'];
$hits+1;
$sql_hit = "UPDATE $table_name
SET hits = \"$hits\"
WHERE bannerID = \"$bannerID\" ";
$result_hit = mysql_query($sql_hit,$connection)
or die("couldn't update database");
header("Location: $ad_url");
exit;
}
?>
i know that's a lot to look through, and i thank anyone for their help... the script does redirect perfectly, but the value of $hits never changes from the initial "0" in the database.
any ideas why it might not be logging the $hits+1 and doing the update ?
agian, thanks.
// michael