Site icon T4Tutorials.com

Website hits tracker code in PHP MySQL

Website hits tracker code in PHP MySQL

This code of website hits tracker is developed in PHP and linked with MySQLi.
<?php 
$con = mysqli_connect("localhost", "root", "", "counter");
// retreive from database
$sql = "Select * from counter";

$result = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($result);

$id = $row['id'];
$count = $row['count'];

echo '<p>Count # ' . $count .' </p>';
$count = (int)$count;
$count++;
$sqlUp = "update counter set count = '$count'";
mysqli_query($con, $sqlUp);
?>

Database view in PHP Myadmin

Figure: PHP MyAdmin View of Website hits tracker code in PHP MySQLi
Exit mobile version