How to make PHP Visitor Count


In this example i am going to explain how to make PHP Visitor Count using PHP and MySQLi .

index.php

<?php
$servername="localhost";
$username="root";
$password="";
$dbname="traffic";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect My Sql:' .mysql_error());
}

$find_count=mysqli_query($conn,"SELECT * FROM count_number");
while($row=mysqli_fetch_assoc($find_count))
{
$current_count=$row['count1'];
$new_count=$current_count+1;
try{
$sql= "UPDATE count_number SET count1 = '$new_count' where id=1";	
$update_count=mysqli_query ($conn,$sql);
echo $new_count;
}
catch(Exception $e){ echo 'error;'.$e->getMessage(); } } ?>