tlavelle Posted August 14, 2007 Share Posted August 14, 2007 I have a huge form with 40 text input fields. Each text field corresponds to a record in a mysql table and was generated using mysql_fetch_row(). Is there an easy while or for loop i can use to populate the $_Sesssion array for each text input? Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/ Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 Depending on what method the form is using, you can just set the $_SESSION array to the $_GET or $_POST array $_SESSION = $_GET; Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/#findComment-323625 Share on other sites More sharing options...
tlavelle Posted August 14, 2007 Author Share Posted August 14, 2007 How do I then echo off the array values? This doesnt work $_Session=$_POST; echo $_Session; Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/#findComment-323690 Share on other sites More sharing options...
tlavelle Posted August 14, 2007 Author Share Posted August 14, 2007 nor does it work if I echo $_Session[0]; Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/#findComment-323692 Share on other sites More sharing options...
hostfreak Posted August 14, 2007 Share Posted August 14, 2007 Try: <?php foreach ($_POST as $Variable) { $_SESSION[] = $Variable; } ?> Then whatever the field name is, would be the variable. Example: <input name="Name"> Would be $Name Although, the only problem I can see is that it would store the submit input in a variable as well. Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/#findComment-323698 Share on other sites More sharing options...
kenrbnsn Posted August 14, 2007 Share Posted August 14, 2007 Using <?php $_SESSION = $_POST; ?> probably isn't the wisest solution. I would use either <?php foreach($_POST as $fld => $val) $_SESSION[$fld] = $val; ?> or <?php $_SESSION['Posted_values'] = array(); foreach($_POST as $fld => $val) $_SESSION['Posted_values'][$fld] = $val; ?> To see what's in the $_SESSION array, you can to: <?php echo '<pre>' . print_r($_SESSION,true) . '</pre>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/#findComment-323700 Share on other sites More sharing options...
tlavelle Posted August 14, 2007 Author Share Posted August 14, 2007 Thanks Ken, That works! Can you walk me through the logic? Can you narrate what is going on here? $_SESSION['Posted_values'] = array(); foreach($_POST as $fld => $val) $_SESSION['Posted_values'][$fld] = $val; echo '<pre>' . print_r($_SESSION,true) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/64856-how-do-i-take-each-input-from-a-form-and-convert-it-into-a-session-variable/#findComment-323734 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.