brown2005 Posted March 9, 2006 Share Posted March 9, 2006 if ($_GET['id']) {$sq1 = mysql_query("SELECT COUNT(*) AS count FROM ads_hits WHERE hits = '".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."'");if (mysql_result($sql, 0, 'count') > 0){$sql2 ="UPDATE ads_hits SEThits_count= hits_count +1WHERE hits='".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."' ";$updated=true;mysql_query($sql2);echo FINISHED;exit();}else{$sql_2="insert into ads_hits(hits,hits_id,hits_ip,hits_count) values('".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."','".$_GET['id']."','".$_SERVER['REMOTE_ADDR']."','0')";$res=mysql_query($sql_2);echo ADDED;exit();}}i have this code which inserts data into the database, but if the record is allready in the database it does not add 1 to the hits_count. can anyone help? Quote Link to comment Share on other sites More sharing options...
joecooper Posted March 10, 2006 Share Posted March 10, 2006 if ($_GET['id']) {$sq1 = mysql_query("SELECT COUNT(*) AS count FROM ads_hits WHERE hits = '".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."'"); if (mysql_result($sql, 0, 'count') > 0){ $sql2 ="UPDATE ads_hits SET hits_count= hits_count +1 WHERE hits='".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."' "; $updated=true; mysql_query($sql2); die("Finished!");}else{ $sql_2="insert into ads_hits(hits,hits_id,hits_ip,hits_count) values('".$_GET['id']." ".$_SERVER['REMOTE_ADDR']."','".$_GET['id']."','".$_SERVER['REMOTE_ADDR']."','0')"; $res=mysql_query($sql_2);die("Added!");}}heres your code tidyed up a bit, some bits are confusing, and can be done so much better and accuate. if your stuck on this code still, i can remake it for £5. joe@joeyjoe.co.uk (msn) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.