perrij3 Posted August 10, 2009 Share Posted August 10, 2009 This is what I am trying to do. I am trying to create a menu for updating information per person. The first page list all the people. The 2nd page is the menu of areas that can be edited. The 3rd page will have the information that was previously entered so the user can update the information. When the user updates the information on the 3rd page, the user goes back to the 2nd page. This all works fine with passing the correct user ID from the 1st page to the 2nd page to the 3rd page. The problem occurs when the user submits the update and goes back to the 2nd page. I can not figure out how to get the variable for the user ID to pass back to the 2nd page. To get the user ID from the list on the first page, I use the following code: Page 2 if ($_GET) { if (isset($_GET['user_ID']) && is_numeric($_GET['user_ID'])) { $user_ID = $_GET['user_ID']; } else { $user_ID = NULL; } } I have tried setting a session variable for the 3rd page and a hidden field to pass the user ID back to the 2nd page using the $_POST option. What I am trying to do is like this Start on Page 1 Go to Page 2 Go to Page 3 When user submits Page 3 to update the fields, go back to Page 2 so they can edit other options on the menu What is the best way to pass the variable I need back to page 2 once the form is submitted on page 3? Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/169641-passing-the-correct-variable/ Share on other sites More sharing options...
WolfRage Posted August 10, 2009 Share Posted August 10, 2009 First pick a method, no method is better than any other it just depends on which is best for your case. However I would rule out $_GET, although you could have the submit button pass the user ID as the actionand make sure that PHP includes the user ID everytime. If you use $_POST you need to use a hidden field and make sure that PHP includes the user ID everytime. $_SESSION is my personal favorite. In that case make sure you are using session_start() before any other code, and simply set the user ID once and call it for each use. $_SESSION['user_ID']=????; Quote Link to comment https://forums.phpfreaks.com/topic/169641-passing-the-correct-variable/#findComment-894971 Share on other sites More sharing options...
perrij3 Posted August 10, 2009 Author Share Posted August 10, 2009 A session variable would work, the only problem I have is I don't know how to set it on page 1. I generate a list people using this code: <?php while($row = mysql_fetch_assoc($result)) { ?> <tr> <td width="90%"><a href="edit_menu.php?user_ID=<?php echo $row['user_ID'];?>" target="_self"><?php echo $row['FirstName'] . " " . $row['MiddleName'] . " " . $row['LastName'] . " " . $row['SurName']; ?></a></td> </tr> <?php } ?> I use the $_GET method on the second page so I can get the user ID number when it's passed to next page. How do you set up a session variable that will pass the user ID based on whom is selected on page 1 to page 2? Quote Link to comment https://forums.phpfreaks.com/topic/169641-passing-the-correct-variable/#findComment-894980 Share on other sites More sharing options...
Catfish Posted August 10, 2009 Share Posted August 10, 2009 Registering a variable with $_SESSION - http://au2.php.net/manual/en/session.examples.basic.php Quote Link to comment https://forums.phpfreaks.com/topic/169641-passing-the-correct-variable/#findComment-894998 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.