Crimson77 Posted February 24, 2012 Share Posted February 24, 2012 Hi All, I'm running trying to add key and values to an array on multiple pages, but it seems to override the array each time I add variables on the next page, even though the keys are different. Each page has something like this: <label class="yes"><input type="radio" name="form_field[<?php echo "number".$f1; ?>]" value="0" > Yes</label> <label class="no"><input type="radio" checked="checked" name="form_field[<?php echo "number".$f1; ?>]" value="1" > No</label> <label class="unsure"><input type="radio" name="form_field[<?php echo "number".$f1; ?>]" value="2" > Unsure</label> I then collect it as well as other page variables with: session_start(); foreach($_POST as $name => $value) { $_SESSION[$name] = $value; } on all following pages. But rather than adding to the array it writes over it each time. Any ideas on what's going wrong here. Should the array simply be able to continue to collect the keys or do I need to do something else? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/257680-session-array-issue/ Share on other sites More sharing options...
Drummin Posted February 24, 2012 Share Posted February 24, 2012 Is this what you're looking for? <?php session_start(); if (isset($_POST['submit'])){ foreach($_POST['form_field'] as $name => $value) { $_SESSION[$name][] = $value; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257680-session-array-issue/#findComment-1320714 Share on other sites More sharing options...
AyKay47 Posted February 24, 2012 Share Posted February 24, 2012 radio names do not need to be an array since the nature of radio buttons is for only one to be selected. Quote Link to comment https://forums.phpfreaks.com/topic/257680-session-array-issue/#findComment-1320813 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.