ggensale Posted September 11, 2009 Share Posted September 11, 2009 I'm trying to create a dynamic $_Session variable by: $_Session[$i] = "value"; After I post my form the session variable in gone. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/173958-dynamic-_session-variable-help/ Share on other sites More sharing options...
Alex Posted September 11, 2009 Share Posted September 11, 2009 Make sure session_start(); is at the top of every page you want to access the session variables from. Quote Link to comment https://forums.phpfreaks.com/topic/173958-dynamic-_session-variable-help/#findComment-916977 Share on other sites More sharing options...
play_ Posted September 11, 2009 Share Posted September 11, 2009 I'm trying to create a dynamic $_Session variable by: $_Session[$i] = "value"; After I post my form the session variable in gone. Any ideas? Are you using session_start() on top of the page? Do you have any $_POST with the same names? (in this example, $_POS[$i]) Quote Link to comment https://forums.phpfreaks.com/topic/173958-dynamic-_session-variable-help/#findComment-916978 Share on other sites More sharing options...
ggensale Posted September 11, 2009 Author Share Posted September 11, 2009 I do have session_start(); Here is a better explaination of what I'm doing...I have another page in which a user will fill out a form asking them how many "items" for each section do they want to create. That gets posted to the new page... And here is the code I'm using to store them: foreach($_POST as $section => $value) { if ($value > 0) { $_SESSION[$section] = "$value"; } } Quote Link to comment https://forums.phpfreaks.com/topic/173958-dynamic-_session-variable-help/#findComment-916979 Share on other sites More sharing options...
kratsg Posted September 12, 2009 Share Posted September 12, 2009 Wouldn't it be easier to just do $_SESSION = $_POST;? Quote Link to comment https://forums.phpfreaks.com/topic/173958-dynamic-_session-variable-help/#findComment-916983 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.