Creating a website counter

I am trying to create a website counter which inserts the information into my database, and displays it on my website also. I am testing it first in localhost so that is why I using localhost as my website. Here is my code.

		 // Connects to your Database 
		 mysql_connect("http://localhost/counter.html", "root", "######password") or die(mysql_error()); 
		 mysql_select_db("db#####") or die(mysql_error()); 
		//Adds one to the counter 
		mysql_query("UPDATE counter SET counter = counter + 1");
		//Retreives the current count 
		$count = mysql_fetch_row(mysql_query("SELECT counter FROM counter"));
		//Displays the count on your site
		 print "$count[0]"; ?>

and this is the is the html with the php include() I am trying to use to get the counter to appear on the website.

    <title>counter test</title>
      <?php include("http://localhost/counter.php"); ?> 

All help greatly appreciated. Codin:rofl::rofl:

You can try too it gives you the counter and site stat which can help you out.

Firstly if you want a page by page counter I would rename the db table to counters, and have rows for each page:

  • name | counter
  • name | counter

Secondly, it looks like it should work. Does it work? What is your question?

I would probably use something along the lines of…


It would allow much better analytics. :slight_smile: