Hi,

I have created a form in which people can select items from a dropdown box, press a button and then their selection is transferred via javascript to another select box. The idea is that users can select items, add them to the list and upon submitting the form, these entries also get POST'ed to the next page. Unfortunately, only 1 item gets through to the next page, and that is usually the first item listed.

I digged a little further and noticed that this is perfectly normal behavior in html. Great, but i really need to have all items transferred to the next page. How can i accomplish this?

errtu

    Maybe u show us your code ...

      Its simple... base it on the following code:

      <?php
      //firstpage.php:
      
      session_start();
      if($_POST["gender"] <> 0) {
      $_SESSION["gender"] == $_POST["gender"];
      }
      else {
      unset($_SESSION["gender"];
      }
      if($_POST["age"] <> 0) {
      $_SESSION["age"] = $_POST["age"]);
      }
      else {
      unset($_SESSION["age"];
      }
      if($_SESSION["gender"] <> 0 && $_SESSION["age"] <> 0 && isset($_POST["submit"])) {
      header("Location: secondpage.php");
      }
      
      echo "<form method=post action=firstpage.php>
      <select name=gender>
      <option value=0>Select a Gender</option>
      <option value=1>Male</option>
      <option value=2>Female</option>
      </select>
      <select name=age>
      <option value=0>Select an Age Range</option>
      <option value=1>0 - 10</option>
      <option value=2>10 - 20</option>
      <option value=3>20 - 30</option>
      <option value=4>30 - 40</option>
      <option value=5>40 - 50</option>
      </select>
      <input type=submit name=submit>
      </form>";
      if($_POST["gender"] == 0 && isset($_POST["submit"])) {
      echo "You did not enter your gender.<br>";
      }
      if($_POST["age"] == 0 && isset($_POST["submit"])) {
      echo "You did not enter your age.<br>";
      }
      
      //secondpage.php
      
      session_start();
      echo "Gender: ".$_SESSION["gender"]."<br>Age: ".$_SESSION["age"];
      ?>
      

      I am pretty certain this should work.

      Clarkey Boy

        $_SESSION["gender"] == $_POST["gender"];

        Wrong operator used here.

          Yeah... I noticed that but forgot to change it... my bad.

          Clarkey Boy

            Thanks alot for all the replies. I have no time to test it now (too much work), but i'll do so when i manage to find some time and let you know how it turned out.

            Thanks again!

            errtu

              A word of caution about headers - make sure that there is no output before calling a header (that means no tabs or spaces in at the beginning of a line of code, or any text outputted onto the screen, or even setting a title). Also, do not forget to use session_start() to start the session (obviously). This also needs to go at the beginning of the page.

              Clarkey Boy

                a month later

                unset did not closed the brackets also in the code

                unset($_SESSION["age"];

                please close

                unset($_SESSION["age"]);
                  12 days later

                  Well I seem to remember that I was in a hurry to write the reply as I was about to go out or something... now fixed.

                  Clarkey Boy

                    Write a Reply...