Author Topic: Need help with a simple hit counter...  (Read 345 times)

Matt

  • Guest
Need help with a simple hit counter...
« on: August 16, 2010, 07:12:48 PM »
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 Code: [Select]
<?php
$DBConnect 
=@mysqli_connect("localhost""root""password")
Or die (
"<p>Unable to connect to the database server.</p>"
"<p>Error code " mysqli_connect_errno()
": " mysqli_connect_error()) . "</p>";
$DBName "hit_counter";
if (!
mysqli_select_db($DBConnect$DBName)) {
	
$SQLstring ="CREATE DATABASE $DBName";
	
$QueryResult = @mysqli_query ($DBConnect$SQLstring)
	
	
Or die(
"<p>Unable to execute the query.</p>"
	
	
"<p>Error code" mysqli_errno($DBConnect)
	
	
": " mysqli_error($DBConnect)) . "</p>";
}
$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(
"<p>Unable to create the table.</p>"
	
	
"<p>Error code" mysqli_errno($DBConnect)
	
	
": " mysqli_error($DBConnect)) ."<p>";
}
$SQLstring "INSERT INTO $TableName VALUES(NULL)";
$QueryResult = @mysqli_query($DBConnect$SQLString)
 or die(
"<p>Unable to execute the query.</p>"
 
"<p>Error code " mysqli_errno($DBConnect)
 . 
":" mysqli_error($DBConnect)) . "</p>";
$Hits mysqli_insert_id($DBConnect);
echo 
"<h1>There have been $Hits hits to this page!</h1>";
mysqli_close($DBConnect);
?>

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....

phphelp

  • Administrator
  • Senior Member
  • *****
  • Posts: 780
  • Karma: +3/-0
    • View Profile
    • PHP Help forum
Re: Need help with a simple hit counter...
« Reply #1 on: August 17, 2010, 02:01:30 AM »
I do not any loop in the provided piece of code. Are you getting any error/warning message?
Are you experienced in PHP programming and willing to share your knowledge?
Join us at php help forum!