You might want to note that this is not the most effective manner of creating a counter in PHP. On a few of my websites, I find it is much more effective to simply create a text file, eg. counter.txt and have PHP read that every time the page is loaded, instead of running a MySQL query. Then, have PHP also update the counter.txt file by adding 1 to the number already listed in the file and read to the user.
These lines
mysql_connect(''$host'', ''$username'', ''$password'')or die(''cannot connect to server '');
mysql_select_db(''$db_name'')or die(''cannot select DB'')
$tbl_name=''counter''; // Table name
$sql=''SELECT * FROM $tbl_name'';
say that you need mysql database. user name, password and table in that database called counter....
So if you do please change parameters if you don't, dont yuse this script, use just some site with free simple counter for your site, which is maintained on their site
Then, the best way is to wrap it into some function, include that code in homepage and call function from somewhere in page where you want it to be seen , for ex.
function counter()
{
//copy counter code here
}
?>.....
See this page for includes, don't change function call.
http://www.w3schools.com/PHP/php_include...
in your case
×
13,412 views
Usually answered in minutes!
sorry i forgot to say that i have that all setup
just didnt want my username and password getting out :)
should the path to the counter.php go in here i got the counter.php in a folder called counter because i keep getting the error ... PHP Fatal error: Call to undefined function counter()
i did what you said now im just getting an error .... Fatal error: Call to undefined function counter()
×