woodplease Posted January 27, 2011 Share Posted January 27, 2011 i'm creating a page counter which updates a value in a database each time the page is loaded. I'm trying to make it so that it checks to see if a session has been set, if not, it updates the database, and then sets the session. This way it wont update every time someone refreshes the page. $id=$_GET['id']; if(!isset($_SESSION[$id])){ $_SESSION[$id]= $id; $views = $row['views'] + 1; $update_views=mysql_query("UPDATE topic SET views='".$views."' WHERE topic_id='".$id."'") i want to set the session variable as that of the page id ($id) The problem is that it keeps updating the database everytime the page is reloaded. I'm not sure if i'm setting the session variable correctly. Any ideas would be great Thanks Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 do you have session_start() somewhere above that code? Quote Link to comment Share on other sites More sharing options...
woodplease Posted January 27, 2011 Author Share Posted January 27, 2011 yes, right at the top, first line Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 can we see all relevant code? Quote Link to comment Share on other sites More sharing options...
woodplease Posted January 27, 2011 Author Share Posted January 27, 2011 its ok, i've fixed it now, turns out i needed to add some quotes to the variable if(!isset($_SESSION["'$id'"])){ $_SESSION["'$id'"]= $id; Thanks anyway Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 that doesn't make sense, but whatever works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.