Jump to content

Hit Counter


ChompGator

Recommended Posts

Im getting a parse error on line 150 of my hit counter, here is the script, line 150 says this:

$sql="SELECT * FROM $tbl_name";            Any suggestions on how to fix this?

 

Here is the error, and the full script below that

Parse error: parse error, unexpected T_VARIABLE in d:\hosting\member\aiim\newaiim.php on line 150

 

 

here is the full script:

 

<?php
$host="**"; // Host name 
$username="**"; // Mysql username 
$password="***"; // Mysql password 
$db_name="**"; // Database name 
$tbl_name="counter"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server "); 
mysql_select_db("$db_name")or die("cannot select DB")

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
$counter=$rows['counter'];

// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";
$result1=mysql_query($sql1);
}

echo "You 're visitors No. ";
echo $counter;

// count more value
$addcounter=$counter+1;
$sql2="update $tbl_name set counter='$addcounter'";
$result2=mysql_query($sql2);

mysql_close();
?>

Link to comment
https://forums.phpfreaks.com/topic/96321-hit-counter/
Share on other sites

Great that worked! I will include my script below, my next question is, if I wanted to put some intelligence behind the hit counter, like only have it go up one hit everytime a computer from a new IP address visits the site, what would I add into the script to make the hit counter do that? Please post any tips, Im going to google it too and see what I get for results! Thanks

 

<?php

$host="***"; // Host name

$username="***"; // Mysql username

$password="***"; // Mysql password

$db_name="login"; // Database name

$tbl_name="counter"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");

mysql_select_db("$db_name")or die("cannot select DB");

 

$sql="SELECT * FROM $tbl_name";

$result=mysql_query($sql);

 

$rows=mysql_fetch_array($result);

$counter=$rows['counter'];

 

// if have no counter value set counter = 1

if(empty($counter)){

$counter=1;

$sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";

$result1=mysql_query($sql1);

}

 

echo "You are visitor Number";

echo $counter;

 

// count more value

$addcounter=$counter+1;

$sql2="update $tbl_name set counter='$addcounter'";

$result2=mysql_query($sql2);

 

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/96321-hit-counter/#findComment-493054
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.