Jump to content

Need Help with php-mysql hit counter


dreglo

Recommended Posts

I found a script that I'm trying to use as a work-around for what I REALLY want. It's a "simple" (not for me) hit counter based on mysql. The creator of the script did give instructions on how to install it but I know I'm doing something wrong ( seeing as I know NOTHING about PHP or mysql), Here is the script:

 

<?php

 

///////////////////// DSCRIPTS PRESENTS /////////////////////////////////////

// //

// This script has been downloaded from http://dscripts.awardspace.com //

// --------------------------------------------------------------------- //

// //

// Script Name: MySQL Hit Counter //

// Written on: 5 January 2007 //

// Written by: Burhan Uddin //

// //

// Browse: http://dscripts.awardspace.com for more free scripts. //

// //

/////////////////////////////////////////////////////////////////////////////

 

$page = $_GET['page'];

 

 

// Exits script if page id isn't supplied

if(!$page)

{

echo 'document.write(\'Invalid Page ID\')';

exit();

}

 

// MySQL Informations. Change it to yours

$host = 'localhost'; // Host Name

$user = 'root'; // User Name

$pass = 'admin'; // Password

$db = 'test'; // Database Name

 

 

 

//---------------------------------------------

// Don't edit below

 

 

/*

This query is required to be executed using phpMyAdmin to create a table for storing data

 

CREATE TABLE `mysql_couter_logs` (

`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,

`name` TEXT NOT NULL ,

`hits` INT NOT NULL DEFAULT '0'

)

*/

 

// Connection to database

$db = mysql_connect($host, $user, $pass) or die ( 'Failed to connect with database!' );

mysql_select_db($db) or die ("Can't select database!");

 

$query= "SELECT id, hits FROM `mysql_couter_logs` WHERE page = '$page'";

$result = mysql_query($query) or die ("document.write('Error in getting hit counts!')");

 

 

while ($data = mysql_fetch_array($result))

{

$id = $data[id];

$count = $data[hits];

}

 

 

 

$count = $count+1;

echo 'document.write(\''.$count.'\');';

 

$query = "UPDATE mysql_couter_logs SET hits = '$count' WHERE page = '$page'";

$result = mysql_query($query) or die ("document.write('Error in storing hit counts!')");

 

?>

 

Here is the Javascript to show the number on the selected page:

 

<SCRIPT LANGUAGE="Javascript" SRC="counter.php?page=pagename"><!--//--></SCRIPT>

 

I also set up the database table as instructed in phpmyadmin.

 

All this and no results so I know it's me.

 

Here is the URL of the page where I want the number to appear (in the box that has "For restaurant use only" in it, under the header "Certificate #"

http://metrodetroitrestaurantguide.com/index.php?option=com_content&view=article&id=11:cert-template&catid=15:gc

Any help or guidance would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/157424-need-help-with-php-mysql-hit-counter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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