Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Multiple Form Processing

    I am developing a web site where there are 4 pages of form information the user needs to fill out. I want the user to go through the first page form, press process, the form gets processed and if no errors, displays the next form. I looked everywhere for answers and haven't found a solution. The code is like what is below.

    Everything works fine on the first form, data is put in the db, everything is fine except for displaying the second form. The "header" command gives the following warning:
    Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\url.com\httpdocs\Test\newclient.php:3) in C:\Inetpub\vhosts\url.com\httpdocs\Test\newclient.php on line 29

    Line 29 is the header command line.

    Any suggestions or alternatives would be very helpful and very grateful! Thanks in advance!
    cyclist-don

    Below is the code...


    <?php
    if (!isset($_POST['firstname'])){
    ?>

    <form name="thisform" action="newclient.php" method="POST">
    First Name: <input type="text" name="firstname" maxlength="30" size="30"><br>
    Last Name: <input type="text" name="lastname" maxlength="30" size="30"><br>
    <input type="submit" value="Submit Information" name="Submit"></TD>
    </form>

    <?php
    }else{

    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];

    //database connection is here

    $query = "INSERT IGNORE INTO client_info
    SET firstname = '$firstname',
    lastname = '$lastname'";
    @mysql_query($query);
    if (mysql_errno() == 0) {
    header("Location: newclient-details.php");
    } else {
    echo "**** unable to add Client Info, error = ".mysql_errno(),"<br>";
    }
    }
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    Without testing this ...
    Try this:

    PHP Code:
    <?php 
    if (!isset($_POST['firstname'])){ 
    echo

    <form name='thisform' action='newclient.php' method='POST'>
    First Name: <input type='text' name='firstname' maxlength='30' size='30'><br>
    Last Name: <input type='text' name='lastname' maxlength='30' size='30'><br>
    <input type='submit' value='Submit Information' name='Submit'></TD>
    </form>
    "
    ;

    }else{

    $firstname $_POST['firstname'];
    $lastname $_POST['lastname'];

    //database connection is here

    $query "INSERT IGNORE INTO client_info 
    SET firstname = '$firstname',
    lastname = '$lastname'"
    ;
    @
    mysql_query($query);
    if (
    mysql_errno() == 0) {
    header("Location: newclient-details.php");
    } else {
    echo 
    "**** unable to add Client Info, error = ".mysql_errno(),"<br>";
    }
    }
    ?>

    I'm thinking that by leaving PHP, doing some HTML and coming back to PHP,
    it's putting data into the HTML header, thus causing the header error.
    Just a shot in the dark...

  • #3
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tried your suggestion. I am still getting the same warning. Also, I forgot to mention that I tried suppressing the warnings and only a blank screen appeared. Thanks for the suggestion!

    cyclist-don

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Is there ANY output before the header command? Even a newline or space can cause this error message.

    Alternatively you could just use a meta redirect:
    PHP Code:
    echo '<meta http-equiv="refresh" content="0;url=nextpage.php" /><a href="nextpage.php">Click here if you are not redirected automatically</a>'

  • #5
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I doubled checked and there were no spaces or any data being displayed.

    The redirect worked fine, thanks!

    Would you recommend a different way of doing what I am trying to achieve?

    Thanks for all your help!

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    Another shot at it ...

    Try this, with an "exit" inserted:

    PHP Code:
    <?php  
    if (!isset($_POST['firstname'])){  
    echo
    "  
    <form name='thisform' action='newclient.php' method='POST'> 
    First Name: <input type='text' name='firstname' maxlength='30' size='30'><br> 
    Last Name: <input type='text' name='lastname' maxlength='30' size='30'><br> 
    <input type='submit' value='Submit Information' name='Submit'></TD> 
    </form> 
    "


    }else{ 

    $firstname $_POST['firstname']; 
    $lastname $_POST['lastname']; 

    //database connection is here 

    $query "INSERT IGNORE INTO client_info  
    SET firstname = '$firstname', 
    lastname = '$lastname'"

    @
    mysql_query($query); 
    if (
    mysql_errno() == 0) { 
    header("Location: newclient-details.php"); 
    exit;
    } else { 
    echo 
    "**** unable to add Client Info, error = ".mysql_errno(),"<br>"


    ?>

  • #7
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I added the exit in after the header statement, as you had shown. The error message was the same.

    I am wondering if there may be a better method to do this or stick with the meta redirect. Any help or suggestions would be greatly appreciated.

    Thanks for all your help!

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I tried suppressing the warnings and only a blank screen appeared.
    It's a bad idea to just suppress warnings, but when you get a blank screen it means you have a syntax error that prevents the script from even starting.

  • #9
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    When I have a large form, instead of splitting it over several pages I have it submit to itself and then decide whereabouts in the process we are, if there were any errors in validation and therefore what part of the form to display.

    e.g.
    PHP Code:
    <?php
    if(!$_POST || ($_POST['form'] == 'first_part' && $err == 1)) {
    ?>
    <form action="page.php" method="post">
    <input type="hidden" name="form" value="first_part" />
    ...
    </form>
    <?php } elseif($_POST['form'] == 'first_part' || ($_POST == 'second_part' && $err == 1)) { ?>
    <form action="page.php" method="post">
    <input type="hidden" name="form" value="second_part" />
    ...
    </form>
    <?php ?>

  • #10
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree with you about suppressing warnings. The syntax for the header statement is as shown in previous posts. Also, when I changed from the header command to the meta redirect, everything worked fine.

    I am just trying to find a different solution so I didn't have to use the meta redirect.

    Thanks for the help!

  • #11
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    You might not have seen my post ^^^ as we both submitted a reply at more or less the same time.

  • #12
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the post regarding one program to process all of the 4 forms of data. This is a good option as well. Over a large amount of data and forms, this could get overwhelming for 1 program. Thanks for the recommendation!

  • #13
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by cyclist-Don View Post
    Thanks for the post regarding one program to process all of the 4 forms of data. This is a good option as well. Over a large amount of data and forms, this could get overwhelming for 1 program. Thanks for the recommendation!
    Not overwhelming at all, as the form is processed bit by bit. Have a seperate script that does all the validation and processing. Use a similar elseif statement block to determine which part of the form has been submitted and requires processing.

  • #14
    New to the CF scene
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try output buffering. Lookup ob_start() and ob_end_flush() in the manual.

  • #15
    New to the CF scene
    Join Date
    Feb 2008
    Location
    Moab, UT
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great ideas and options. Thanks to all. I will be trying all the options. At least now I have options. Thanks again for the help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •