This is probably elementary, but here goes. I need to pass the same variable between a couple forms, and am not sure of the best way to do this using PHP. Example:
page1.php has a button that takes you to the next page. Using an <a href="...", the URL includes the id, and looks something like this: "www.mydomain.com/page2.php?my_id=2". This is working perfectly.
page2.php uses a $_GET['my_id'] to get that number 2, and does whatever it needs to do with the information. That much is also working perfectly.
page2.php also includes yet another button that will pass yet another variable to page3.php. something like: "www.mydomain.com/page3.php?another_id=4"
What I need is to have 'my_id' (from page1.php, used in page2.php) available in page3.php. I can use the $_GET to access 'another_id', but I can't seem to figure out how to also have access to 'my_id' originally generated from the page1.php.
Is using the superglobals the way to go here, and if so, can I get a sample line of code to show how to keep 'my_id' available? Or is there another technique I am overlooking?
thanks much,
tc
Passing a parameter/variable between pages
Moderator: General Moderators
Re: Passing a parameter/variable between pages
You can insert the value of $_GET['my_id'] into the link
Or you could use session data or cookies.
Code: Select all
<a href="www.mydomain.com/page3.php?my_id=<?php echo $_GET['my_id']; ?>&another_id=4">Link</a>Re: Passing a parameter/variable between pages
Thank you!! worked like a charm. Didn't realize you could pass more than one variable on the URL line. Am good to go!
tc
tc