Pjack125 Posted December 5, 2008 Share Posted December 5, 2008 I am trying to set a list of variable and making sure they don't get overwritten when the page get refreshed. I know we can use isset for one session variable like so. if(isset($_SESSION['PMpage'])) echo ""; else $_SESSION['PMpage'] = $_POST['PMPageID']; but how would i go about doing this for a list for example $_SESSION['EVMS'] = $_POST['EVMS']; $_SESSION['ReportCard'] = $_POST['ReportCard']; $_SESSION['PMRiskMan'] = $_POST['PMRiskMan']; $_SESSION['PRR'] = $_POST['PRR']; $_SESSION['Contracts'] = $_POST['Contracts']; $_SESSION['SubContracts'] = $_POST['SubContracts']; how would i go about doing so would i need to use some sort of a switch such as if(isset($_POST['PassedPost'])){ echo "";} else { foreach($_POST as $key => $val) { $_SESSION[$key] = $val; } } I know it would be something similar to the above but i just can't figure out how to get it to work because the end result should be as soon as we submit the form to page.php?dept=EE the data from previous page say page1.html should be stored in saved into session variables. then page.php is loaded again except as page.php?dept=ME what I am trying to do is store data posted by page1.html without it getting overwritten and then do the same for page.php?dept=EE . Is this possible if so how would i go about writing it? Link to comment https://forums.phpfreaks.com/topic/135685-using-isset-on-multiple-session-variable/ Share on other sites More sharing options...
bgadberry Posted December 5, 2008 Share Posted December 5, 2008 When you say "store" it, how are you storing it? Just in variables for use with something else? or in a database? If its a database, just add the session variables to the database, and then it wouldnt matter if you overwritten the session variables as they would be in the DB. Else if its just stored into session variables for later usage, then consider using different variables, example: <?php $dept=$_GET['dept']; if ($dept=='EE') { if(isset($_SESSION['PMpage'])) { $_SESSION['EE_PMpage']=$_POST['PMPageID']; } //add for each variable } elseif ($dept=='ME') { if(isset($_SESSION['PMpage'])) { $_SESSION['ME_PMpage']=$_POST['PMPageID']; } //add for each variable } ?> Add the variables in for each session var you want to store, then later on, address them by their name; You could probably could make a foreach loop to go through all the POST vars passed and add them to session rather than checking for each particular POST variable as I believe they are only passed if something is there to be passed, and then do something with them at that point. Not sure if that would help as Im not too sure as to what your intentions are, but its a try. Perhaps it will lead you to your goal. More information would be helpful, perhaps like, what you are planning to do with the information once its stored, etc. Link to comment https://forums.phpfreaks.com/topic/135685-using-isset-on-multiple-session-variable/#findComment-706947 Share on other sites More sharing options...
Pjack125 Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks I haven't tested it yet but I think this should work. everything will be stored in a database letter on but i need to generate a preview page of all the results using session variables first then all those variable information after the user approves will be stored to the database. Link to comment https://forums.phpfreaks.com/topic/135685-using-isset-on-multiple-session-variable/#findComment-709337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.