phpretard Posted April 18, 2008 Share Posted April 18, 2008 I need to set these variable multiple time with different values. They are set via form submit. There are many forms and each form could have different values. Can anyone help me do this without have to write the code over and over and over... $_SESSION['picture']=$picture; $_SESSION['size'] =$size; $_SESSION['quantity'] =$quantity; $_SESSION['file']=$file; $_SESSION['time'] = date('m-d-Y'); Thank you. Link to comment https://forums.phpfreaks.com/topic/101636-session-1/ Share on other sites More sharing options...
ohdang888 Posted April 18, 2008 Share Posted April 18, 2008 you just re define them $_SESSION['picture']=$picture; then later on... $_SESSION['picture']=$new_picture; Link to comment https://forums.phpfreaks.com/topic/101636-session-1/#findComment-520028 Share on other sites More sharing options...
AP81 Posted April 18, 2008 Share Posted April 18, 2008 You can use an array with the $_SESSION array. ie: <?php $pictures = array("1.jpg", "2.jpg", "3.jpg"); $_SESSION['picture']=$pictures; ?> Link to comment https://forums.phpfreaks.com/topic/101636-session-1/#findComment-520029 Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Each form submission needs to create a new session variable and also hold on to the last one. form submitted: $_SESSION['picture']='1234'; $_SESSION['size'] ='4x6'; $_SESSION['quantity'] ='10'; $_SESSION['file']=$file; $_SESSION['time'] = date('m-d-Y'); In the same session another form is submitted by the same person: $_SESSION['picture']='5678'; $_SESSION['size'] ='8x10'; $_SESSION['quantity'] ='20'; $_SESSION['file']=$file; $_SESSION['time'] = date('m-d-Y'); This could happen many times. After someone is finished submitting all the forms...all the variables are emailed. Link to comment https://forums.phpfreaks.com/topic/101636-session-1/#findComment-520032 Share on other sites More sharing options...
AP81 Posted April 18, 2008 Share Posted April 18, 2008 <?php $pictures = $_SESSION['picture']; $size = $_SESSION['size']; // and so on // then add the new elements $pictures[] = "1.jpg"; $size[] = "large"; // ... // now set the session again with the array $_SESSION['picture']=$pictures; $_SESSION['size']=$size; ?> Link to comment https://forums.phpfreaks.com/topic/101636-session-1/#findComment-520037 Share on other sites More sharing options...
phpretard Posted April 18, 2008 Author Share Posted April 18, 2008 Sorry for being so ignorant... How can I put all this in one array? // POSTS $picture=$_POST['picture']; $S46=$_POST['S46']; $QU46=$_POST['QU46']; $S57=$_POST['S57']; $QU57=$_POST['QU57']; $S810=$_POST['S810']; $QU810=$_POST['QU810']; $file=$_POST['file']; //END POSTS // ARRAY STARTS HERE $_SESSION['S46'] =$S46; $_SESSION['QU46'] =$QU46; $_SESSION['S57'] =$S57; $_SESSION['QU57'] =$QU57; $_SESSION['S810'] =$S810; $_SESSION['QU810'] =$QU810; $_SESSION['picture']=$picture; $_SESSION['file'] =$file; $_SESSION['time'] =date('m-d-Y'); //ARRAY ENDS HERE OK... Now all the info above is in an array (which Im not 100% on). How do I save that array and add a new one with different values. I'm am a little confused. Link to comment https://forums.phpfreaks.com/topic/101636-session-1/#findComment-520043 Share on other sites More sharing options...
Zane Posted April 18, 2008 Share Posted April 18, 2008 Here's an alternative to you're dilemna \\ Variable Names $theVars = array(); $theVars[] = "S46"; $theVars[] = "QU46"; $theVars[] = "S57"; $theVars[] = "QU57"; $theVars[] = "S810"; $theVars[] = "QU810"; $theVars['time'] = date('m-d-Y'); foreach($theVars as $var=>$key) { if(isset($_POST[$var])) { $_SESSION[$var] = $_POST[$var] //You really don't need the line below...it just makes a new variable for all those items in your POST array. ${$var} = $var; } else { $_SESSION[$key] = $_POST[$key]; ${$key} = $var; } Link to comment https://forums.phpfreaks.com/topic/101636-session-1/#findComment-520050 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.