I am trying to mess with different ways to do a hit counter. I currently have two files. Hit Counter and Count visits. Count visits calls hit counter and hit counter creates a table and increments it. I am not getting any output and I think it is in my create table or somewhere around there. This is my hit counter file
class HitCounter {
private $DBConnect;
private $DBName = "ngarrett_MIS4530A";
private $TableName = "4530-p5-iabarker"; private $Hits = 0;
function __construct() {
$TableName = "4530-p5-iabarker";
$DBName = "ngarrett_MIS4530A";
$this->DBConnect = @new mysqli("localhost", "**********", "**********"); if (mysqli_connect_errno())
die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
// The following code creates a table if one does not exist $SQLstring = "USE $DBName";
$QueryRsult = @mysqli_query($this->DBConnect, $SQLstring); $SQLstring = "SELECT * FROM $4530-p5-iabarker";
// See if table exists
$QueryResult = @mysqli_query($this->DBConnect, $SQLstring);
mysql_query("CREATE TABLE countertable( count INT(8))")or die("Create table Error: ".mysql_error());
}
function __destruct() {
// Closes the database connection
$this->DBConnect->close();
}
public function setDatabase($Database) {
$this->DBName = $Database; @$this->DBConnect->select_db($this->DBName)
Or die("<p>Unable to select the database.</p>"
. "<p>Error code " . mysqli_errno($this->DBConnect) . ": " . mysqli_error($this->DBConnect)) . "</p>";
}
public function setTable($4530-p5-iabarker) {
$this->TableName = $4530-p5-iabarker;
}
public function setHits() {
//code to increment the hit counter and save the result in the table
}
public function getHits() {
}
and here is my count visits file that calls the hit counter
<?php
require_once("HitCounter.php");
?>
<h1>Hit Counter</h1>
<?php
echo "<p>There are _______ hits</p>";
$Database = "ngarrett_MIS4530A"; $Table = "4530-p5-iabarker";
if (class_exists("HitCounter")) {
$Counter = new HitCounter(); $Counter->setDatabase($Database);
} else
exit("<p>The HitCounter class is not available!</p>"); $Counter->setTable($4530-p5-iabarker);
$Counter->getHits();
$Counter->setHits();
//code to display counter goes here
mysql_query("UPDATE 4530-p5-iabarker SET count=count+1");
?>