phpmysqldatabasecountvisitors

Count Visitors in PHP and Save to Database


I Got 4 Pages, each page must count how many times it is visited and it must be saved to the database.

I have no idea how to do it. I got database name = "

qr_database

Table name =

colors

Column Names =

Cyan, Magenta, Yellow, Black

This way i connect :

<?php
        $mysqli = mysqli_connect("127.0.0.1", "root", "usbw", "qr_database", 3307);
        if (mysqli_connect_errno($mysqli)) {
            echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }
        ?>

This is 1 of the color pages :

<?php
$pagetitle = "QR-Company";
include "includemeta.php";
require("database.php");
?>
<body id="Cyaan" id="banana">
</body>
</html>

I hope you understand what i mean!


Solution

  • $sql = "UPDATE colors SET Yellow=Yellow+1";
    

    Do what vlzvl said. Then use this query for every page. Just make sure your replace Yellow with the color for the specific page.