Molson31 Posted June 10, 2013 Share Posted June 10, 2013 I am using jqforms to create simple forms and populate them from SQL data. This works fine when hard coded (eg search for ID with value x). However when I try to populate from $_GET values, it does not work, and I am going insane trying to understand why. First there is a simple PHP with my website menu (Main.php). Then it php-includes the php file (Form.php) containing my form. <?php include ("Form.php");?> This works and the forms work 100%. The URL accessed: www.website.com/Main.php?val=10254 In Form.php there is a simple SQL Select command. 'SELECT OrderID, ShipName FROM orders WHERE OrderID = '. $value .''; Above this, as a test, the $value is simply hardcoded. $value = 10254; This loads the database perfectly to the correct ID. It echoes this exact line (I realize echo will break the rest of the code, but just to test the output): SELECT OrderID, ShipName FROM orders WHERE OrderID = 10254 Okay. So everything is fine. Now here is the problem. Replace the hard-coded $value with: $value = $_GET['val']; It will echo this: SELECT OrderID, ShipName FROM orders WHERE OrderID = 10254 Which as you can see is the exact same thing as hard coded. And yet, remove the echo, and it will not load. What the hell is going on? I have lost 2 days so far because of this! It is literally echoing the same thing so why does it do nothing? My only guesses are how the value is being passed, and something to do with including the Form.php in the Main.php. The only reason I do that is that is how the jqform works (it for some reason does not work if you copy-paste the Form.php contents into Main.php... weird). Thank you for any help. Quote Link to comment https://forums.phpfreaks.com/topic/279002-absolutely-losing-my-mind-over-simple-_get-statement/ Share on other sites More sharing options...
teynon Posted June 10, 2013 Share Posted June 10, 2013 You need to post all the code. You also need to ensure that error reporting is on and you need to do some debugging. One typical thing I do for debugging is put little echo $myvar; die(); at a point. Then run the script and see what the variable is at that point (or see if it's getting into that block of code). I do this throughout various parts of the application and it saves me a lot of time. Without any other code or debugging, your post above will have moved you no closer to an answer. Quote Link to comment https://forums.phpfreaks.com/topic/279002-absolutely-losing-my-mind-over-simple-_get-statement/#findComment-1435191 Share on other sites More sharing options...
Molson31 Posted June 10, 2013 Author Share Posted June 10, 2013 Without any other code or debugging, your post above will have moved you no closer to an answer. well I figured it out. At least I made a dirty code that works. But Typing this out did help! So check it out. For whatever reason (probably old/lazy design, because the rest of the stuff is fantastic) you have to set a paramater in jqform (and jqgrid) that points to the url/filename of the file itself. Kind of redundant but it does not work with out it. So if you had Form.php included in your Main.php, in Form.php you must set this variable: $newForm->setUrl('Form.php'); The problem was, after this is called, my query becomes useless as it no longer is looking at the query run in Main.php (such as Main.php?value=1235) So my workaround: first I have to GET the value passed from the URL, then post that in to the setUrl, the GET that again and post it in the SELECT command. Here is the solution I will keep for the records. $firstVal = $_GET['RealValue']; $newForm->setUrl('Form.php?val='. $firstVal .''); $value = $_GET['val']; $newForm->SelectCommand = 'SELECT OrderID, ShipName FROM orders WHERE OrderID = '. $value .''; Quote Link to comment https://forums.phpfreaks.com/topic/279002-absolutely-losing-my-mind-over-simple-_get-statement/#findComment-1435197 Share on other sites More sharing options...
Maq Posted June 10, 2013 Share Posted June 10, 2013 I would assume you're supposed to setUrl before submission. Quote Link to comment https://forums.phpfreaks.com/topic/279002-absolutely-losing-my-mind-over-simple-_get-statement/#findComment-1435202 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.