Jump to content


PHP Help!


7 replies to this topic

#1 FK69

    Young Padawan

  • Members
  • Pip
  • 57 posts
  • Location:Melbourne, Australia

Posted 27 July 2005 - 08:31 AM

Hey im trying to put a Hits counter on my site now i made a MySQL database and all that but i keep getting this error

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home2/sgfxhost/public_html/show_hits.php on line 7

How do i fix this? some1 please help me

The code is below i got it off GreyCobra.com

Connect.php
<?php
//Connect.php
$connect = mysql_connect(“LocalHost”,”Username”,”Password”) or die(“Failed to connect to database“);
$db = mysql_select_db(“database”) or die(“Failed to connect to database“);
?>

add_hits.php
<?php
//add_hits.php
Include(“connect.php”);
$IP = $_SERVER[‘REMOTE_ADDR’];
$referer = $_SERVER[‘HTTP_REFERER’];
$time = time();
$date = date(“M, d, Y”);
$add_stats = mysql_query(“INSERT INTO stats(IP,referer,time,date) VALUES (‘$ip’, ‘$referer’, ‘$time’, ‘$date‘)”);
?>

Set_hits.php
<?php
//set_hits.php
Include(“connect.php”);
$date = date(“M, d, Y”);
$unique_hits_select = mysql_query(“SELECT DISTINCT ip FROM stats”);
$unique_hits_nr = mysql_num_rows($unique_hits_select);
$unique_hits_today_select = mysql_query(“SELECT DISTINCT ip FROM stats WHERE date = ‘$date’”);
$unique_hits_today_nr = mysql_num_rows($unique_hits_today_select);
$total_hits_select = mysql_query(“SELECT * FROM stats”);
$total_hits_nr = mysql_num_rows($total_hits_select);
$total_hits_today_select = mysql_query(“SELECT * FROM stats WHERE date = ‘$date’”);
$total_hits_today_nr = mysql_num_rows($total_hits_today_select);
?>

Show_hits.php
<?php /* Created on: 27/07/2005 */ ?>
<html>
<body background="images/main_content.png">
<font color="#90DEFF" face=verdana size="1">
<?php
//show_hits.php
Echo “Total Unique hits: “ $unique_hits_nr;  <BR>
Echo “Today’s Unique hits: “ $unique_hits_today_nr; <BR>	
Echo “Total hits: “ $total_hits_nr; <BR>	
Echo “Total hits today: “ $total_hits_today_nr; <BR>	
?> 
</font>
</body>
</html>

Can someone tell me what im doing wrong here?

Thank you.

Edited by FK69, 27 July 2005 - 08:33 AM.


#2 softLearner

    Young Padawan

  • Members
  • Pip
  • 128 posts

Posted 27 July 2005 - 08:35 AM

this code:
<?php
//show_hits.php
Echo “Total Unique hits: “ $unique_hits_nr;  >BR>
Echo “Today’s Unique hits: “ $unique_hits_today_nr; <BR>
Echo “Total hits: “ $total_hits_nr; <BR>
Echo “Total hits today: “ $total_hits_today_nr; <BR>
?>
should be:
<?php
//show_hits.php
echo "Total Unique hits: ".$unique_hits_nr."<br>";
echo "Today’s Unique hits: ".$unique_hits_today_nr."<br>";
echo "Total hits: ".$total_hits_nr."<br>";
echo "Total hits today: ".$total_hits_today_nr."<br>";
?>

That should sort you problems, when wve you want join a variable onto a string do it like this: echo "sometext ".$variable." some more text"; or you could do it like so: echo "sometext $variable some more text";

Also for some reason all your "" (quotes) seem to be “” insetead of " ", should straight double quotes. If its not then it must be the forum doing that then

Edited by softLearner, 27 July 2005 - 08:39 AM.


#3 FK69

    Young Padawan

  • Members
  • Pip
  • 57 posts
  • Location:Melbourne, Australia

Posted 27 July 2005 - 08:41 AM

Ok that worked to some degree now all i got is:

Total Unique hits:
Today’s Unique hits:
Total hits:
Total hits today:

The numbers dont show even though i've clicked on the page like 3-5 times.

#4 fiv3isaliv3

    Young Padawan

  • Members
  • Pip
  • 258 posts
  • Gender:Male

Posted 27 July 2005 - 12:55 PM

if you want the stats to display self_hits.php should be on the same page as show_hits.php... just do

<?
require "self_hits.php";
?>

make sure you add it to the show_hits.php page...

Edited by zealivity5, 27 July 2005 - 12:55 PM.


#5 FK69

    Young Padawan

  • Members
  • Pip
  • 57 posts
  • Location:Melbourne, Australia

Posted 28 July 2005 - 06:50 AM

and what would be in this self_hits.php? orwould it just be blank im not really sure like a i said im a n00b at php lol.

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 29 July 2005 - 01:12 PM

Well, i do believe that the guy had a spelling error, and meant to: require 'set_hits.php'; Not self_hits

#7 FK69

    Young Padawan

  • Members
  • Pip
  • 57 posts
  • Location:Melbourne, Australia

Posted 29 July 2005 - 11:10 PM

i got it fixed neways had to include add_hits.php and set_hits.php and i gforgot to add the user to the database lol

#8 FK69

    Young Padawan

  • Members
  • Pip
  • 57 posts
  • Location:Melbourne, Australia

Posted 30 July 2005 - 07:28 AM

well atleast i thought i had it fixed the Unique Hits counter isnt changing and i know i got a couple of people onto the site to look at it...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users