clowny Posted January 19, 2013 Share Posted January 19, 2013 (edited) 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 January 19, 2013 by clowny Quote Link to comment https://forums.phpfreaks.com/topic/273368-phpmysql-order-of-processing/ Share on other sites More sharing options...
trq Posted January 20, 2013 Share Posted January 20, 2013 The simple answer is: Each time you hit a submit button your making a new request to the server. Variables do not persist across requests. Quote Link to comment https://forums.phpfreaks.com/topic/273368-phpmysql-order-of-processing/#findComment-1406996 Share on other sites More sharing options...
kicken Posted January 20, 2013 Share Posted January 20, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273368-phpmysql-order-of-processing/#findComment-1406997 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.