counting number of visits per page ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tokentag
Forum Newbie
Posts: 2
Joined: Wed Apr 10, 2013 6:20 pm

counting number of visits per page ID

Post by tokentag »

Code: Select all

<?php
session_start();
$id=(int) $_GET['id'];
if(!isset($_SESSION['$id'])){
$_SESSION["'$id'"]=$id;
$sql = "UPDATE table SET fldVisits = fldVisits + 1 WHERE fldID ='$id' LIMIT 1";
mysql_query($sql) or die(mysql_error());
echo 'fldVisits'
?>
fldID is the ID of the pages. Ex. .php?id=1, .php?id=2 etc..
fldVisits is the fld Visits column in the database. fldVisits is where +1 is added for each visit by sessions.

I am getting a syntax error. I suppose im writing the wrong quotes. What am I doing wrong here?
Last edited by tokentag on Wed Apr 10, 2013 7:15 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: counting number of visits per page ID

Post by requinix »

Missing a closing }.

But you're also getting your strings messed up.

Code: Select all

if(!isset($_SESSION['$id'])){
Variables don't work in single-quoted strings.

Code: Select all

$_SESSION["'$id'"]=$id;
You've got an extra pair of quotes in there.


Next time you post PHP code, please use

Code: Select all

 tags. It makes the code easier to read and even adds some syntax highlighting.
tokentag
Forum Newbie
Posts: 2
Joined: Wed Apr 10, 2013 6:20 pm

Re: counting number of visits per page ID

Post by tokentag »

Thanks for the reply. I fixed up the PHP code and the colors are there.
Post Reply