php - Displaying database information on a page -
i'm building unique hits counter project count go 1 if users ip isn't in database, how implement "count" html?
php
<?php $connect_error = 'sorry, we\'re experiencing connection problems.'; mysql_connect('localhost', 'root', 'password') or die($connect_error); mysql_select_db('hit_counter_database') or die($connect_error); $user_ip = $_server['remote_addr']; function ip_exits($ip){ global $user_ip; $query = "select `ip` `hits_ip` `ip` = '$user_ip'"; $query_run = mysql_query($query); $query_num_rows = mysql_num_rows($query_run); if($query_num_rows) ==0) { return false; }else ($query_num_rows) >= 1){ return true; } } function ip_add($ip) { $query = "insert `hits_ip` values ('$ip')"; @$query_run = mysql_query($query); } function update_count(){ $query = "select `count` `hits_count`"; if (@$query_run = mysql_query($query)){ $count = mysql_result($query_run, 0, 'count'); $count_inc = $count + 1; $query_update = "update `hits_count` set `count` = '$count_inc'"; $query_update_run = mysql_query($query_update); } } if(!ip_exists($user_ip){ update_count(); ip_add($user_ip); } ?>
Comments
Post a Comment