timmah1 Posted December 10, 2008 Share Posted December 10, 2008 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 Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/ Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 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"); Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711806 Share on other sites More sharing options...
timmah1 Posted December 10, 2008 Author Share Posted December 10, 2008 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 />"; } Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711821 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 Indeed. Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711826 Share on other sites More sharing options...
timmah1 Posted December 10, 2008 Author Share Posted December 10, 2008 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 Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711837 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 while (list ($name,$val) = @each ($_POST['package_'])) { $total += $val; $_SESSION['SESS_NAME'][] = $name; $_SESSION['SESS_PRICE'] = $total; } Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711843 Share on other sites More sharing options...
timmah1 Posted December 10, 2008 Author Share Posted December 10, 2008 That does a lot better now, at least it's showing 5 items, but it's showing the last item, and this below it. Array Array Array Array Array Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711851 Share on other sites More sharing options...
trq Posted December 10, 2008 Share Posted December 10, 2008 What is in $_POST['package_'] ? Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711860 Share on other sites More sharing options...
timmah1 Posted December 10, 2008 Author Share Posted December 10, 2008 $_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. Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711865 Share on other sites More sharing options...
timmah1 Posted December 10, 2008 Author Share Posted December 10, 2008 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 Link to comment https://forums.phpfreaks.com/topic/136410-multiple-sessions-same-name-different-values/#findComment-711878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.