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.

<?php
		 // 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.

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

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

You can try http://www.statcounter.com/ 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:
counters

  • 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…


page_view.time
page_view.user_ip
page_view.user_agent
page_view.page
page_view.referrer

It would allow much better analytics. :slight_smile: