Page 1 of 1

counting number of visits per page ID

Posted: Wed Apr 10, 2013 6:24 pm
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?

Re: counting number of visits per page ID

Posted: Wed Apr 10, 2013 7:08 pm
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.

Re: counting number of visits per page ID

Posted: Wed Apr 10, 2013 7:25 pm
by tokentag
Thanks for the reply. I fixed up the PHP code and the colors are there.