mysterious disappearing variable using $_GET
Posted: Tue Nov 16, 2010 4:31 pm
Pounding my head on wall for last 3 hours, figure I better get some hints from experts...
I use $_GET method to obtain some IDs I need in my program. Generally working fine.
In this case, I use this: $last_cat = $_GET['category_id']; at the top of my php file. I can check this value upon starting the file - it is perfect.
The page itself is mostly an HTML form. I can check the value of the variable $last_cat at the end of the form (once it is displayed on screen), and it shows the value perfectly. So - going into the form, the value is legit.
However, upon saving the form, the value of $last_cat goes blank - it should be a 1, 2, 3 or 4, and suddenly it is nothing.
I call the save button like this: <input type="submit" class="bottom" value="save" /> Pretty standard stuff. Following clicking the Save button, there is some more code that initiates the actual data validation and saving routings. It is here I can test for the value and see that is it GONE.
if ($_SERVER['REQUEST_METHOD']=='POST') {
...do some validation things...
...save the data in the form...
...send the use to another page using: header("Location:somefile.php?attach_id=".$data_obj->att_id."&category_id=".$last_cat);
}
If I check for the value of $last_cat inside this "if" statement, using a simple Echo $last_cat; and Exit; function, I can see the value is gone. Obviously, I put this mini-debug check BEFORE the last line where it sends the user to another page. Indeed, the "header(...)" function works fine for the attach_id value (which comes from a value in a table, not a variable), but not for the category_id.
The problem is not in the "header" statement/function per se. As mentioned, the value of $last_cat is gone apparently as soon as I click on the "Save" HTML button or as soon as the program enters the "if" statement. I don't know why this is.
is there something happening upon submitting a form that I need to know? Any workaround if so? Do I need to create a "hidden" html line to temporarily store the value in $last_cat? If so, how would I do that (I've tried but no apparent success).
Thanks so much,
TC
I use $_GET method to obtain some IDs I need in my program. Generally working fine.
In this case, I use this: $last_cat = $_GET['category_id']; at the top of my php file. I can check this value upon starting the file - it is perfect.
The page itself is mostly an HTML form. I can check the value of the variable $last_cat at the end of the form (once it is displayed on screen), and it shows the value perfectly. So - going into the form, the value is legit.
However, upon saving the form, the value of $last_cat goes blank - it should be a 1, 2, 3 or 4, and suddenly it is nothing.
I call the save button like this: <input type="submit" class="bottom" value="save" /> Pretty standard stuff. Following clicking the Save button, there is some more code that initiates the actual data validation and saving routings. It is here I can test for the value and see that is it GONE.
if ($_SERVER['REQUEST_METHOD']=='POST') {
...do some validation things...
...save the data in the form...
...send the use to another page using: header("Location:somefile.php?attach_id=".$data_obj->att_id."&category_id=".$last_cat);
}
If I check for the value of $last_cat inside this "if" statement, using a simple Echo $last_cat; and Exit; function, I can see the value is gone. Obviously, I put this mini-debug check BEFORE the last line where it sends the user to another page. Indeed, the "header(...)" function works fine for the attach_id value (which comes from a value in a table, not a variable), but not for the category_id.
The problem is not in the "header" statement/function per se. As mentioned, the value of $last_cat is gone apparently as soon as I click on the "Save" HTML button or as soon as the program enters the "if" statement. I don't know why this is.
is there something happening upon submitting a form that I need to know? Any workaround if so? Do I need to create a "hidden" html line to temporarily store the value in $last_cat? If so, how would I do that (I've tried but no apparent success).
Thanks so much,
TC