Hi all

I got 3 questions, I need help with:

  1. I am developing an application for people that have no idea what they are doing. In other words I have to keep it as simple as possible. The user is required to fill out a couple of forms. The forms are very simple and spread over a few pages. That is, the user fill out one form, click save and then the page shift to a new page with the next form.

So far I have included a header at the end of the form script that calls the next page with the next form. But that is a problem if the users PHP ini file has "output buffer=off". Then you can only send two headers before your are met with the error "can not modify header allready sent etc".

Is there a more elegant way of having the page change to a new page with a new form as soon as the user click the save button. A coding example is highly appricatet.

  1. Function lib:
    According to my PHP book, you can have a single file with all your functions. Then your able to include that function file in your scripts. But how do you inwoke the third function in the function file and use it in a script? A coding example is highly appricatet.

  2. Slashes:
    As far as I know you need to have double slashes in your PHP scripts in order for the scripts to work on both Windows and Linux. Is that true?

Thanks in advance.

    Once you have included the comon functions file with an INCLUDE or REQUIRE statement then you just call any function in it by name, as always.

      Many ways to do this. A simple approach is to have the form post to page2. Page2 would save the data to the db and then display form 2, which would post to page 3 etc.

      // page1
      <body>
      <form <form name="form1" action="page2.php" method="post">
      <input type="text" name="user">
      <input type="text" name="q1">
      <input type="text" name="q2">
      etc
      <input type="submit" name="save1" value="next page">
      </form>
      </body>
      
      //page2
      
      <?php
      session_start;
      $_SESSION['user']=$_POST['user'];
      $_SESSION['q1']=$_POST['q1'];
      $_SESSION['q1']=$_POST['q2'];
      
      //either now or all at once when user finishes
      $sql="INSERT INTO table VALUES('$user', '$q1', '$q2')";
      
      // run query and check for errors etc
      
      include 'header.php';
      ?>
      
      <body>
      <form <form name="form2" action="page3.php" method="post">
      <input type="hidden" name="user" value="<?=$_SESSION['user']?>">
      <input type="text" name="q3">
      <input type="text" name="q4">
      etc
      <input type="submit" name="save2" value="next page">
      </form>
      </body>
      
      

      Example only this code will not work as is.

        Thanks a lot.

        What are you doing with this:
        include 'header.php';

          I always have a header.php. It contains all the stuff that I need to have at the top of each page, eg db connect, access control, common functions, html header and <head> standardised across the site.

          I just then need to include it at the beginning of every page.

            Clever, never thought that you could do that. But then again, I have been learning PHP for about 2 weeks now.

              Use require_once and then you don't have to worry about functions etc being loaded twice even when assembling pages from code-fragment files.

                Write a Reply...