Jump to content

Absolutely losing my mind over simple $_GET statement


Molson31

Recommended Posts

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.

 
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 Without any other code or debugging, your post above will have moved you no closer to an answer.

 

:D 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 .'';
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.