ChompGator Posted March 15, 2008 Share Posted March 15, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 15, 2008 Share Posted March 15, 2008 Your missing a semi-colon after this line mysql_select_db("$db_name")or die("cannot select DB") Quote Link to comment Share on other sites More sharing options...
ChompGator Posted March 15, 2008 Author Share Posted March 15, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
helraizer Posted March 15, 2008 Share Posted March 15, 2008 Make the IP address the primary key, or at least if not primary key, make it unique. That way it can only be in the database once, therefore it fits your problem. Sam Quote Link to comment Share on other sites More sharing options...
ChompGator Posted March 15, 2008 Author Share Posted March 15, 2008 Oh wow, so I dont have to add any complex extra scripting! Good stuff, ok thanks! Quote Link to comment Share on other sites More sharing options...
MAGiK602 Posted March 15, 2008 Share Posted March 15, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.