I'm writing my own banner management system. As a result, I will be updating a db to calculate impressions/clicks. I will need to do this several times throughout the site, therefore, I thought I would create a function to perform the update and just call the function.
Below is my function and how I'm calling it. For some reason, it isn't executing the update. Can someone help?
Code:
<?php
function banner_stats($banner_id, $banner_location) {
$update_banner = "INSERT INTO banner_stats (location, impressions, banner_id) VALUES('$banner_location',impressions + 1, $banner_id)";
mysql_query($update_banner, $connection) or die(mysql_error());
}
?>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
The $connection variable is not defined in your function, so you either need to (a) pass it as another function parameter, (b) declare it as global within the function, or (c) just leave it out of the mysql_query() call if you only have one connection established in your script (and thus can just let it use that one by default).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks