Jump to content
Larry Ullman's Book Forums
ROY2

Losing $_Get Values After Pressing Reload Button

Recommended Posts

Larry,

 

First time poster. Just starting out with PHP, finding your PHP for the Web:Visual QuisckStart Guide exactly what I need to help me understand how to do PHP. I plan to purchase your advanced version of PHP and SQL as soon as I finish this book.

 

I have written an inquiry program with one page for the header and another for the detail. When a link for the line item on the first page is clicked, I pass the order# associated with that line item via the URL to the second page as a $_GET.  On the second page, I use a $_GET for the order# and use that order# in my SQL statement. This works fine, it brings up all the detail lines associated with that header order#.

 

However, I have a drop down selection on that second screen where the user can select to display only a certain status type. After the page has been displayed the first time, if they make a selection and then press a reload button on that screen, the order# is now blank and the query fails.

 

I have a session_start; at the very beginning of the 2nd screen.

 

This is my $_GET stmt:

$ordernbr = $_GET["ordernbr"];

 

This is my query select stmt:

$query_stmt = "SELECT * FROM MYLIB/SOMEFILE where f1dsorn = $ordernbr";

 

This is my reload statement:

<input type="submit" class="button" value="Reload">

 

I have an echo of the $ordernbr, and when the Reload button is pressed the value becomes null.

 

Does anyone have any suggestions how to save the $ordernbr when the reload button is pressed?

 

Thanks in advance.

Roy

Share this post


Link to post
Share on other sites

Hello, Roy. Welcome to the forums. I hope you find them helpful.

I think you have a few options:

 

1) Store the $ordernbr value in a hidden input in the form on the second page, and then grab that value from the $_POST superglobal when you post the form with the "Reload" button.

 

2) Save the $ordernbr into a cookie or session.

 

3) Use JavaScript and Ajax to change part of the form dynamically without actually reloading the page. (This is rather advanced and not really recommended. I more am just presenting it here because it is a possibility.)

 

Of the three options, I probably wouldn't attempt #3 unless you want a serious challenge.

#2 is a very viable option, but I'm not sure if Larry talks about cookies/sessions in the book, so I'd check that first.

So that leaves us with option #1.

 

Basically, when you are using PHP to write the HTML for the form on the second page, add am extra hidden input element (I think Larry talks about these in the book) with a value equal to the $ordernbr variable. That way, when you post the second form by clicking the "Reload" button, that $ordernbr value will be posted and accessible in the $_POST superglobal under the name set for the hidden input.

Does that make sense?

  • Upvote 3

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...