I seem to be having an issue with this script. Im pretty sure its in my if statement but i cant figure out what is wrong. Any one see anything obviously wrong ?
$ip_address = $_SERVER['REMOTE_ADDR'];
$user_name = $_SESSION['user_name'];
$url = $_SERVER['REQUEST_URI'];
$tokens = explode('/', $url);
$image_id = $tokens[sizeof($tokens)-1];
//Connect to the database
include 'db_connect.php';
$sql_1 = "SELECT * FROM tracking_table";
$statement = $db->prepare($sql_1);
$statement->execute(array());
while($row = $statement->fetch(PDO::FETCH_ASSOC))
{
$compare_id = $row['image_id'];
$count = $row['count'];
}
if ($compare_id != $image_id) {
$sql_2 = "INSERT INTO tracking_table (image_id, user_name, ip_address, count)
VALUES (?, ?, ?, ?)";
$statement = $db->prepare($sql_2);
$statement->execute(array($image_id, $user_name, $ip_address, 0));
}
else if ($compare_id == $image_id){
$count = $count++;
$sql_3 = "INSERT INTO tracking_table (count)
VALUES (?)";
$statement = $db->prepare($sql_3);
$statement->execute($count);
}