Jump to content

Multiple sessions - same name, different values


timmah1

Recommended Posts

How can you set a session to have the same name, but different values?

Is this possible?

 

This is for a order page, now the user has the option to pay with credit card, or PayPal

Here is what I ahve

while (list ($name,$val) = @each ($_POST['package_'])) {
$total += $val;
session_register("SESS_NAME");
session_register("SESS_PRICE");

$_SESSION['SESS_NAME'] = $name;	
$_SESSION['SESS_PRICE'] = $total;
}

How can I get the $_SESSION['SESS_NAME'] to be all the items they selected?

 

Thanks in advance

How can I get the $_SESSION['SESS_NAME'] to be all the items they selected?

 

Store an array within it.

 

Also note that session_register has long been depricated. You can remove the lines....

 

session_register("SESS_NAME");
session_register("SESS_PRICE");

Thanks thorpe

 

So something like this

$names=array($name);

$_SESSION['SESS_NAME'] = $names;	
$_SESSION['SESS_PRICE'] = $total;

 

Then to display it like this?

foreach($_SESSION['SESS_NAME'] as $key=>$value)
    {
    // and print out the values
    echo "$value<br />";
    }

Doing this

foreach($_SESSION['SESS_NAME'] as $key=>$value)
    {
    // and print out the values
    echo "$value<br />";
    }

only shows the last one.

 

I selected 5 different items, and the last one is the only one showing

$_POST['package_'] is pulled from the order page

<input name="package_[<?=$a[name]; ?>]" type="radio" value="<?=$price;?>">

 

Once they get to the order page, they have a choice to pay with PayPal, or credit card.

If they pay with credit card, they stay on that page, if they want PayPal, they click a link to fill out the form

and I only want to retain the packages they ordered to that page.

I figured it out

I had this

$names=array($name); 
$_SESSION['SESS_NAME'][] = $names;   
$_SESSION['SESS_PRICE'] = $total;

 

But if I do this

$_SESSION['SESS_NAME'][] = $names;   
$_SESSION['SESS_PRICE'] = $total;

 

It works just like it should

 

Thank you for all your help thorpe

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.