jeff5656 Posted March 31, 2008 Share Posted March 31, 2008 I want to carry a variable from page to page and use it to display certain records in a table. The form is simply <form name="physician" method="post" action="displayreminders.php"> <table><tr><th>Physician (last name only)</th></tr> <tr><td> <input type="text" name="physician" id="physician" /></td></tr> <tr><td><input type="submit" value="Submit"></td></tr></table></form> The php action file (displayreminders.php) correctly displays all records WHERE $physician is same as the _POST. However, if I go to a new form and try to pre-populate it with $physician, it does not work. On the new form I have: if (isset($_POST['physician'])) $physician = $_POST['physician']; else $physician = ''; But when I echo $physician, it is blank! How do I retain that original variable value all the way until a user closes the browser? Thanks in advance... Link to comment https://forums.phpfreaks.com/topic/98888-carrying-a-_post-variable-from-page-to-page/ Share on other sites More sharing options...
AdRock Posted March 31, 2008 Share Posted March 31, 2008 register a session from a the post variable tehn you can pass it from page to page Link to comment https://forums.phpfreaks.com/topic/98888-carrying-a-_post-variable-from-page-to-page/#findComment-505995 Share on other sites More sharing options...
metrostars Posted March 31, 2008 Share Posted March 31, 2008 You will have to set in a session variable. You cannot keep a $_POSt variable. <?php if(isset($_POST['physician'])) { $_SESSION['physician'] = $_POST['physician']; $physician = $_POST['physician']; } elseif (isset($_SESSION['physician'])) { $physician = $_SESSION['physician']; } else { $physician = ''; } ?> and make sure you put session_start(); at the top of every page you intend to use this session value. Link to comment https://forums.phpfreaks.com/topic/98888-carrying-a-_post-variable-from-page-to-page/#findComment-505997 Share on other sites More sharing options...
jeff5656 Posted April 1, 2008 Author Share Posted April 1, 2008 and make sure you put session_start(); at the top of every page you intend to use this session value. Ok thanks. One other question: on subsequent pages that I use session_start, how do I refer to the variable? Do I simply use $physician OR or do I say $physician = $_POST['physician']; OR do I say $physician = $_SESSION['physician']; Link to comment https://forums.phpfreaks.com/topic/98888-carrying-a-_post-variable-from-page-to-page/#findComment-506060 Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 The $_SESSION array will be populated automatically on session_start() with previously defined session variables... so you last response would be correct. Next time, though, you can just test it for yourself. Try print_r($_SESSION) to output your currently defined session variables. Link to comment https://forums.phpfreaks.com/topic/98888-carrying-a-_post-variable-from-page-to-page/#findComment-506063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.