Forum Moderators: coopster

Message Too Old, No Replies

Code doesn't run on 1st page load, intermittently

Code doesn't run on 1st page load, intermittently

         

knippysing

7:42 pm on Mar 25, 2010 (gmt 0)

10+ Year Member



I created a "wizard" of sorts using forms & php. Each page asks a question, then the following page stores the data into MySQL db and asks some more questions. As it's continuing on the path, certain variables are to be carried to each page through hidden form fields.

On a couple of pages, I noticed that it forgets these persistent variables once in a while when I first arrive to the page. When/if I refresh, (and repost form) it remembers what it was supposed to and away we go. And it's not all the time either. It's hit and miss.

I'm really puzzled on this deal. I've tried to sleep(); once in a while so it has time to think before it starts loading and that doesn't seem to work. I put the main PHP code at the end of a page and that seemed to work fine, however I need the information at the top in order for the rest of the page to work.

Any thoughts as to why this is happening?

rocknbil

7:51 pm on Mar 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without further details . . . are you setting session variables that preclude or trigger any actions? If so, these may be "getting in the way" of expected behavior.

If you use cookies in any way to control anything, this may also be creating havoc. Especially true if it works fine after closing the browser. A cookie set without an expire time (or incorrectly set expire time and path, which will make it a session cookie) is a good example.

Matthew1980

7:59 pm on Mar 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Knippysing,

Pages of questions, keeping data from previous page? This is a prime example for the use of the $_SESSION['store_value_here'] sessions. Unless you are already doing this.

I notice as you are storing this info in a DB, and using hidden fields to hold data, the use of sessions here would be ideal. As you are probably aware, once a session var is isset, its there for the entire script as its a super global.

Unless I have misunderstood your situation, $_SESSION would be the solution, then once the data is collected, then you can insert the data, and once the insert is done just use unset($_SESSION['name']); to clear the data. ;-p

At least that is the way I would do this, I'm not saying either that the way you are doing it is wrong, just offering another option there for you to consider.

Cheers,
MRb