Jump to content

Recommended Posts

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.