Bean Boy Posted October 13, 2008 Share Posted October 13, 2008 Hey Guys, I've been at this for hours and tried everything I know, but nothing's working. This code rotates headlines and counts the impressions of each one. But when I click to the next page, the $_SESSION variable seems to increment by one? WTF!? <? session_start(); $result = mysql_query("SELECT * FROM headline ORDER BY impressions") or die(mysql_error()); $row = mysql_fetch_array( $result ); $headline = $row['headline']; $impressions = $row['impressions'] + 1; // COUNT IMPRESSION $result2 = mysql_query("UPDATE headline SET impressions='$impressions' WHERE headline='$headline'") or die(mysql_error()); $_SESSION['headline'] = $headline; echo "<h1>\"" . $_SESSION['headline'] . "\"</h1>"; echo "<a href=nextpage.php> Click-Through</a>"; ?> And here's the next page: <? session_start(); print $_SESSION['headline']; ?> If $_SESSION['headline'] was Headline1, on the next page it becomes Headline2, etc. What's going on here? Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/ Share on other sites More sharing options...
kenrbnsn Posted October 13, 2008 Share Posted October 13, 2008 Do you have register_globals enabled? Ken Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664494 Share on other sites More sharing options...
Bean Boy Posted October 13, 2008 Author Share Posted October 13, 2008 No. I'm not sure what that is. How would I use register_globals? Also, I've never had a problem passing session variables in the past creating codes similar to this one. Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664499 Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 No. I'm not sure what that is. How would I use register_globals? Also, I've never had a problem passing session variables in the past creating codes similar to this one. He asked because you shouldn't have register_globals on. Go to your php.ini or phpinfo() and verify. Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664500 Share on other sites More sharing options...
Bean Boy Posted October 13, 2008 Author Share Posted October 13, 2008 Just checked. Yes, global are set to off. So any idea what's up with my code? The only idea I had was that somehow the code on the first page is running again when I click onto the next page. ??? Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664528 Share on other sites More sharing options...
kenrbnsn Posted October 13, 2008 Share Posted October 13, 2008 What browser are you using? There have been instances that Firefox will start twice, due to DOCTYPE issues. Ken Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664537 Share on other sites More sharing options...
Bean Boy Posted October 13, 2008 Author Share Posted October 13, 2008 Hey Ken. I'm using the latest version of IE. Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664539 Share on other sites More sharing options...
Bean Boy Posted October 14, 2008 Author Share Posted October 14, 2008 I just tried deleting the DOCTYPE lines from my pages and then it worked! Not only that, when I added them again, it seems to work fine. This is just strange. Link to comment https://forums.phpfreaks.com/topic/128283-why-the-does-my-_session-change/#findComment-664557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.