Jump to content

PHP/mySQL order of processing?


clowny

Recommended Posts

Hi people. First post so be gentle. I am a mid level php person - not professional but i can do some pretty neat stuff. One thing i never learned though which is handcuffing me, is the basics on what gets processed first, and i'm having a nightmare at the moment. Let me try to explain, as it's complicated. I won't bore you with the intricacies of what I'm trying to do as it's not really too relevant i think. I'll just outline how my code is set up and probably one of you will know immediately where i screwed up :

 

basically i have a clause at the top of my script that does one database operation if submit1 button is pressed, and another if submit2 is pressed. inside the submit2 clause is a php script that needs a variable (let's call it $variable1). Now down at the bottom of the html body, i have a data form. it's populated with some data from a recordset (not so relevant here). i have a php line down in that area that says $variable1=$row_theRecordset['theFieldIwant']. Not being an expert, i would *think* that would do the trick, and then when i hit submit2 that $variable1's value would then be available to the php script up top in the submit2's script area. But no, and this is what is stumping me.

 

I have tried to troubleshoot it by echoing the values of the variable at different stages. immediately after it's been assigned it's fine and echoes out the value i'd expect. echo it out up top when submit is pressed however, and no dice.

 

i suspect it might have something to do with the fact it's being called at the top of the page, but being defined at the bottom, but that seems counterintuitive since the submit code isn't called until i press the button, and by then the variable has been given the right value. am i missing something? Like I said i've confirmed that none of the code itself is faulty; use hardwired values and everything works perfect. it's passing the variable that is causing the problems. help?

Edited by clowny
Link to comment
Share on other sites

Every request is completely independent of any previous (or future) requests.   The variables you set during one request are not set during any other request (general exception is $_SESSION variables). 

 

Generally speaking the scripts simply run in a top-down fashion, from line 1 to line X, whatever that may be.  Each time the script starts it's execution at line 1, the environment is completely clean as if that script (or any other) had never been run before.

 

If you want to use something, you have to ensure that it is made available prior to your attempt to use it.  This means you either have to pass the data from script to script (ie, using $_SESSION, $_POST, $_GET, etc) or you have to re-acquire that data from the database/file/whatever.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.