Jump to content

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.

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'HOSTGATOR' (1) in /home/dreglo/public_html/metrodetroitrestaurantguide/counter.php on line 49

Failed to connect with database!

 

http://metrodetroitrestaurantguide.com/counter.php?page=1

 

It is showing that you do not have the right connections in with your database. And please, do not double post.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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