Need help with a simple hit counter...

Hi all college student here, coming to you guys for some help because I think my instructor to an early vacation…(Sent him an email 2 weeks ago about this and still no response).

The assignment is to make a basic hit counter, the book provides the code for the most part but, from some earlier assignments this book is riddle with code errors (Including some of the examples that come on the data disc)

[php]<?php
$DBConnect =@mysqli_connect(“localhost”, “root”, “password”)
Or die (“

Unable to connect to the database server.


. "

Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . “

”;
$DBName = “hit_counter”;
if (!mysqli_select_db($DBConnect, $DBName)) {
$SQLstring =“CREATE DATABASE $DBName”;
$QueryResult = @mysqli_query ($DBConnect, $SQLstring)
Or die(“

Unable to execute the query.


. “

Error code” . mysqli_errno($DBConnect)
. “: " . mysqli_error($DBConnect)) . “

”;
}
$TableName = “count”;
$SQLstring = “SELECT * FROM $TableName”;
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (!QueryResult) {
$SQLstring = “CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY)”;
$QueryResult= @mysqli_query($DBConnect, $SQLstring)
Or die(“

Unable to create the table.


. “

Error code” . mysqli_errno($DBConnect)
. “: " . mysqli_error($DBConnect)) .”

”;
}
$SQLstring = “INSERT INTO $TableName VALUES(NULL)”;
$QueryResult = @mysqli_query($DBConnect, $SQLString)
or die(“

Unable to execute the query.


. "

Error code " . mysqli_errno($DBConnect)
. “:” . mysqli_error($DBConnect)) . “

”;
$Hits = mysqli_insert_id($DBConnect);
echo “

There have been $Hits hits to this page!

”;
mysqli_close($DBConnect);
?>
[/php]
I need to find why this is getting stuck in a loop?

It just keeps going and going tell eventually it locks the computer up.

Any help would be greatly appreciated.

Most of that is straight from my text book…

I do not any loop in the provided piece of code. Are you getting any error/warning message?

Sponsor our Newsletter | Privacy Policy | Terms of Service