This tutorial will (hopefully, if I can manage to be coherent) show you, my fellow php-er, how to pass a variable through 2 pages.
It doesn't sound very difficult, but it is a mite tricky. The way I used it was to verify information from a form submission. In this case, the user enters their info in a form and clicks
"submit,"
but instead of having the information submitted immediately, it is first displayed to the user again for them to check it. This way, he/she/it has the option of saying, "Oh, suck! I put in the wrong information!" In other case, I have a list of links, and when the user clicks on one, the script shows the person what he/she/it clicked on and asks if that's really what they wanted... we all know how mouse pointers can wander. So, on with the tutorial...
First, I have a basic HTML form, which I'm going to assume you know how to do. When the user clicks the submit button from there, the action is . With that, he/she/it is taken to the page that will check their info.
First, we make sure the temp .txt file can be opened, in "write" mode:
Now we will reopen that file for reading only, then print the information in that file on the displayed page. When php writes to a file, it puts in slashes with any apostrophes, so we have to strip those out of the .txt file so the user doesn't get an ugly, slashed-up version of what he/she/it entered originally:
Now, since all the information is already written to a text file, none of those variables need to be passed through. However, my goal is to have that information emailed to me, and I want the email to be CC'ed to the user. Therefore, I need to pass the $email variable through to the next page. Here's how I did that: The final page's script is as follows... this script emails me the information from the text file and CC's that email to the user who entered it:
That's it. I hope it made sense. Perhaps someday I'll write an even simpler variable-passing tutorial based on my other script, which doesn't use the form. Just let me know if any of you think that would be helpful! However, the basic idea is the same: rename the variable in your tag. Verbosity is a curse.