I have seen a few different ways to solve this problem, but no solution has worked for me. I am logging into a database and incrementing a hit counter when someone goes to the page. I have two files, hitcounter.php and count visits.php Count visits is used by the visitor and is needed to instantiate the hitcounter.php file. The hit counter should open the database and store the hits in a private variable. I have logged in to the database, incremented everything. I just dont know how to get it to count correctly and if I a using a private variable my code is below....
$user_name = "";
$password = "";
$database = "";
$TableName = "";
$DBConnect = @mysqli_connect("", "", "", $)
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
$DBName = "";
if(! $DBConnect )
{
die('Could not connect: ' . mysql_error());
}
$page = $_SERVER['REQUEST_URI'];
$result = mysql_query("SELECT HIT_COUNT FROM Hit_Count WHERE Page_Name = '$page'");
$any = false;
while($row = mysql_fetch_array($result)) {
$any = true;
$counter = mysql_result($result, 0) + 1;
$sql = "UPDATE Hit_Count SET HIT_COUNT = '$counter' WHERE Page_Name = '$page'";
mysql_query($sql);
echo($counter);
}
if($any == false) {
$sql = "INSERT INTO Hit_Count (Page_Name, HIT_COUNT) VALUES ('$page', '1')";
mysql_query($sql);
echo("1");
}
mysql_close($DBConnect);
?>`