Ok, now i am trying to make different forms in different pages like in this example:

first page ----- form 1
----- form 2
----- form 3
----- view all results

So in the first page you will be able to select from among three forms in any order you wan, and then view the results by clicking on the "view all results button".

The forms are simple 5 text inputs.... so how can i be able to make it?, i have tried using Session variables but i don't understand how to use them
can someone help me?

    first off you need to desclare session_start(); under <?php on every script where you want to use your session.

    So you may have something similiar to...

    <?php
    
    //you don't need to declare session_start(); because there are to sessions to create.
    
    echo
    "<form action='page2.php' method='post'>
    Name: <input type='text' name='fname' />
    <input type='submit' value='submit' />
    </form>";
    
    ?>

    On page2.php you would do this

    <?php
    session_start();
    
    //create the session
    $_SESSION['fname'] = $_POST['fname'];
    
    //not needed but shorten the session
    $fname = $_SESSION['fname'];
    
    echo $fname;
    
    ?>

      mmmm.... i´m not so clear about the use of Session variables

      here is my first form:

      <html>
      <head>
      </head>
      <body>
      <form action="form2.php" method="POST">
      <input type="text" name="p1" /><br/>
      <input type="text" name="p2" /><br/>
      <input type="text" name="p3" /><br/>
      <input type="text" name="p4" /><br/>
      <input type="text" name="p5" /><br/>
      <input type="submit" />
      </form>
      </body>
      </html>

      the second one looks like
      <html>
      <head>
      </head>
      <body>
      <form action="form3.php" method="POST">
      <input type="text" name="p6" /><br/>
      <input type="text" name="p7" /><br/>
      <input type="text" name="p8" /><br/>
      <input type="text" name="p9" /><br/>
      <input type="text" name="pa" /><br/>
      <input type="submit" />
      </form>
      </body>
      </html>

      and so on with the other forms.... So should i put the

      <?php
      session_start();

      $SESSION['p1'] = $POST['p1'];

      echo $p1;

      ?>

      at the beggining of form 2? and will that print what the user puts on the first text box of the form 1 or it will only retrieve it?

        Are you getting information from every form then at the end insert everything into the database?
        If so I'll show you an easier method

          If you get result from echoing $p1 like this:

          <?php
          session_start();
          
          $_SESSION['p1'] = $_POST['p1'];
          
          echo $p1;
          
          ?>

          ...that would mean that globals on your server are turned on (generraly, this is not good because everyone can submit those variables as part of URL (GET method) and they'll be treated as SESSION or POST variables and you won't be clear where they come from)...

          My suggestion is after that first step there to simply use the $_SESSION['p1'] and show it where you need to...

          i.e. Use the variables like this:

          <?php
          session_start();
          
          $_SESSION['p1'] = $_POST['p1'];
          
          echo $_SESSION['p1'];
          
          ?>

          This way you can be sure that they come from SESSION that are retrieved from a POST or your form...

          Hope, this helps clear things up a bit...

            i put that code right at the beggining of the form2.php right?, but then, how can i print them on the screen, or just by inputing that code I will see the retrieved data of the previous form?

            Oh and i just want to save the values of the inputs, because i want to make a principal page where you can select from 3 different forms, then fill them, return to the principal page, and then, by clicking on a button called "results" you go to a page that shows all the values from all the forms. So the principal page has 4 buttons (form 1, form 2, form 3, results) and each form returns to the main page.... or is there an easier method rather than using SESSION variables?

              You can echo the variables on what page you want and where you want to show them...

              So you can show them on principal page as you want to just the same as long as you have session_start() on top of every page where user can go and where you want to save this data on...

                i've allready started a session in all my forms and i can display the retrieved information in the next page after filling the form (show the results in "principal page")but i can´t send those values to the "results page" - (i put the same code in the "results page" of declaring the Session variable and then using echo to show the value but it doesn't display the retrieved information)

                  You don't need to use a session for this

                  In your second form add the following code after your opening form tag

                   <input type="hidden" name="p1" value=' ".$_POST['p1']." ' />
                  <input type="hidden" name="p2"  value=' ".$_POST['p2']." ' />
                  <input type="hidden" name="p3" value=' ".$_POST['p3']." ' />
                  <input type="hidden" name="p4" value=' ".$_POST['p4']." ' />
                  <input type="hidden" name="p5" value=' ".$_POST['p5']." '/>

                  Now your second form should like

                   <form action="form3.php" method="POST">
                   <input type="hidden" name="p1" value=' ".$_POST['p1']." ' />
                  <input type="hidden" name="p2"  value=' ".$_POST['p2']." ' />
                  <input type="hidden" name="p3" value=' ".$_POST['p3']." ' />
                  <input type="hidden" name="p4" value=' ".$_POST['p4']." ' />
                  <input type="hidden" name="p5" value=' ".$_POST['p5']." '/>
                  <input type="text" name="p6" /><br/>
                  <input type="text" name="p7" /><br/>
                  <input type="text" name="p8" /><br/>
                  <input type="text" name="p9" /><br/>
                  <input type="text" name="pa" /><br/>
                  <input type="submit" />
                  </form> 

                  What this will do is get the values from the first form and insert them into a hidden form.

                  You repeat this for your third form

                   <form action="form3.php" method="POST">
                   <input type="hidden" name="p1" value=' ".$_POST['p1']." ' />
                  <input type="hidden" name="p2"  value=' ".$_POST['p2']." ' />
                  <input type="hidden" name="p3" value=' ".$_POST['p3']." ' />
                  <input type="hidden" name="p4" value=' ".$_POST['p4']." ' />
                  <input type="hidden" name="p5" value=' ".$_POST['p5']." '/>
                  <input type="hidden" name="p6"  value=' ".$_POST['p6']." ' />
                  <input type="hidden" name="p7"  value=' ".$_POST['p7']." ' />
                  <input type="hidden" name="p8"  value=' ".$_POST['p8']." ' />
                  <input type="hidden" name="p9"  value=' ".$_POST['p9']." ' />
                  <input type="text" name="pa"  value=' ".$_POST['pa']." ' />
                  <input type="text" name="p10" /><br/>
                  <input type="text" name="p11" /><br/>
                  <input type="text" name="p12" /><br/>
                  <input type="text" name="p12" /><br/>
                  <input type="text" name="pb" /><br/>
                  <input type="submit" />
                  </form> 

                  Hopefully you get the idea.
                  Make sure every name is different.

                    What harmor suggests is very true...

                    As for my idea to show values that you stored somewhere in the session just echo them...

                    So, basically when you send your data from the form on the form processing page do the $SESSION['p1'] = $POST['p1'] and so on. BUT only on that page because only on that page you will have the $_POST values you need stored in session variables...

                    Do that on every form processing page (for all forms) and then when you want to show it on the result page just do:

                    echo $_SESSION['p1'];
                    echo $_SESSION['p2'];
                    //and so on
                    

                    But then again maybe the harmor's idea is better and faster for you to get this working...

                      maxp,

                      As a fellow newbie to PHP that has researched this issue far too much over the last couple days, I have stumbled across a magical solution. This was given to me by another fellow developer.

                      The easiest way to do what you're trying to do is with Sessions...
                      Hidden Variables are an option, but what if you decide to make the form 10 pages? Then you'll be copying and pasting variables and having to continually add to them.

                      Anyway, simply copy and paste this code at the top of each page in the form:

                      [INDENT]<?php
                      session_start();
                      foreach($POST as $key => $val)
                      {
                      $
                      SESSION[$key] = $val;
                      }
                      ?>
                      [/INDENT]

                      Then, on your last page when you want to view the variables, you just list the code like this for each variable you want to print, surrounded by <p> tags or whatever you like:

                      [INDENT]<?php echo $var?>[/INDENT]

                      If you need any other code for this, feel free to respond on the boards or drop me a line through other methods. That's all there is to it, though, and it works just great on my form.

                        thanks, now i get how to do it!!
                        using both methods (hidding and using session variables)

                          TymArtist wrote:

                          maxp,

                          [INDENT]<?php
                          session_start();
                          foreach($POST as $key => $val)
                          {
                          $
                          SESSION[$key] = $val;
                          }
                          ?>
                          [/INDENT]

                          I have a similar problem that im trying to soleve- does the code above work- it seems rather short? Also if i wanted to insert all the data into my db how would the final code for inserting data be any different?

                            Yes, it does work. Just because something is short doesn't mean that it doesn't work 🙂. I had the same thoughts when the code was given to me, but in the end it was the only thing that did work for me. Hidden variables weren't something I was going to mess around with. Granted, I'm not sure if there are any security issues with foreach loops and variables/information as I haven't much delved into that end of things, so if anyone can share any information on that it would be nice.

                            I hadn't gotten around to putting this into a database yet, only email, but i'm assuming the code would look something like. We use a separate file for the login data so correct me if i'm wrong, please:

                            [INDENT]<?php
                            $date = date('Y-m-d H:i:s');
                            $Host = "localhost";
                            $User = "username";
                            $Password = "password";
                            $DBName = "databasename";
                            $query = "insert into tablename values
                            ('$var1','$var2','$var3','$etc')";
                            $result = mysql_query($query) or die ('<p>Insert Record: ' . mysql_error());
                            ?>[/INDENT]

                              I have 6 parts to my form namely:

                              1 nottsvcs_common_short
                              2 nottsvcs_placeyourorganisationshort
                              3 nottsvcs_short_1_4a
                              4 nottsvcs_short_1_4b
                              5 nottsvcs_short_1_4c
                              6 nottsvcs_short_1_4d

                              Am I right in saying I should insert the code you suggested a the top of each page then for part 1:

                              <form name="form1" method="post" action="nottsvcs_placeyourorganisation_short.php">

                              part 2

                              <form name="form1" method="post" action="nottsvcs_short_1_4a.php">

                              etc

                              When does the first page nottsvcs_common_short.php get submitted?

                                Tezread wrote:

                                I have 6 parts to my form namely:

                                1 nottsvcs_common_short
                                2 nottsvcs_placeyourorganisationshort
                                3 nottsvcs_short_1_4a
                                4 nottsvcs_short_1_4b
                                5 nottsvcs_short_1_4c
                                6 nottsvcs_short_1_4d

                                When does the first page nottsvcs_common_short.php get submitted?

                                Each page gets submitted to the page after it. So submit 1 to 2, 2 to 3, 3 to 4, and so on. As long as the Session remains open (that is, the user doesn't close the browser) this information will be available for use. Essentially the code you place on the top of each page is keeping everything in an array that's ready to access.

                                  I have tried putting this at the top of each page but it is not working. I would rather use session variables than hidden variables.

                                  <?php
                                  session_start();
                                  foreach($POST as $key => $val)
                                  {
                                  $
                                  SESSION[$key] = $val;
                                  }
                                  ?>

                                  see for yourself- the values are supposed to be stored if you click the previous button on yuor browser.

                                  www.mindseyemidlands.co.uk/nottsvcs_common_short.php

                                    Write a Reply...