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
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
Share on other sites

OR

 

1. You'd need to use the global variable which gets the visitors IP address and then have the IP address adding to a DB or a file.

2. Scan the file or DB for the user currently on the page, if the IP isn't already in the file or DB, add it and +1 to the counter.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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