0) { mysql_connect('localhost','username','password'); mysql_select_db('db'); $output = mysql_fetch_assoc(mysql_query("SELECT downloads, link FROM download WHERE id='$id'")); if(file_exists($output['link'])) { $downloads = $output['downloads'] + 1; mysql_query("UPDATE download SET downloads = '$downloads' WHERE id = '$id'"); $location = 'Location: '.$output['link']; } } header($location); ob_end_clean(); exit(); ?>