<?php 

$dir = '../';

require_once $dir.'includes/main.php';

$id = (int)$_POST['id'];

$user_id = fetch_record("SELECT user_id FROM listings WHERE id = '{$id}' LIMIT 1");

if(fetch_rows("SELECT id FROM clicks WHERE ip = '{$ip}' AND listing_id = '{$id}' AND date_created > {$period['hour']} LIMIT 1") < 1){

   query("INSERT INTO clicks (ip, listing_id, date_created) VALUES ('{$ip}', '{$id}', '{$t}')");

   query("UPDATE listings SET clicks = clicks + 1 WHERE id = '{$id}' LIMIT 1");
   query("UPDATE stats SET clicks = clicks + 1 WHERE user_id = '{$user_id}' ORDER BY id DESC LIMIT 1");
   query("UPDATE _stats SET clicks = clicks + 1 ORDER BY id DESC LIMIT 1");

}

?>