m_tyhurst2002 Posted September 20, 2012 Share Posted September 20, 2012 Hi guys, newb here, trying to get sessions to work form me. I am having difficulty incorporating SESSIONS into my dynamic SELECT OPTION. At the very top of my page I am starting SESSION code and POSTing "people" from the form. <?php session_start(); // start session $totalpeople = $_POST['people']; //post number of tanks from form ?> This is my SELECT OPTION code. <select name="people"> <? for ($i=1;$i<100;$i++) { $selected = ""; if ($i==$totalpeople) $selected = (isset($_SESSION['people']) && $i == $_SESSION['people']) ? ' selected' : ''; print ("<option value='" . $i . "' " . $selected . ">" . $i . "</option>\n"); } ?> </select> Any help or insight would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/268606-sessions/ Share on other sites More sharing options...
shlumph Posted September 20, 2012 Share Posted September 20, 2012 Where/when do you set $_SESSION['people']? Quote Link to comment https://forums.phpfreaks.com/topic/268606-sessions/#findComment-1379594 Share on other sites More sharing options...
m_tyhurst2002 Posted September 20, 2012 Author Share Posted September 20, 2012 I have one page actually, the first option that appears on that page is a SELECT dropdown where they select how many people, and submit. When they submit, it reloads the same page with other options (the first option goes away after submitting). The new options, when clicked on, goes to a PayPal cart. From that cart, when they click "continue shopping" it reloads my page and the user has to select how many people again. I would just like it if the SELECT OPTION remembered how many people they chose the first time. Hope that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/268606-sessions/#findComment-1379596 Share on other sites More sharing options...
shlumph Posted September 20, 2012 Share Posted September 20, 2012 From what I'm understanding, I think you want this: <?php session_start(); // start session $_SESSION['people'] = $_POST['people']; //post number of tanks from form ?> And then adjust your select box, by getting rid of if ($i==$totalpeople) Quote Link to comment https://forums.phpfreaks.com/topic/268606-sessions/#findComment-1379602 Share on other sites More sharing options...
coded4u Posted September 20, 2012 Share Posted September 20, 2012 Bad move, you need to secure the $_POST[] before you throw it into a session. any posted data from a user should be checked/cleaned & made secure. Failing to do so a user can inject code into the post, cause a lot of damage depending on what you have running in your php & what the person injects. Quote Link to comment https://forums.phpfreaks.com/topic/268606-sessions/#findComment-1379759 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.