SitePoint Sponsor

User Tag List

Results 1 to 18 of 18

Thread: Error Checking

  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error Checking

    I have a page that I need to do error checking on, then if everything's OK I have to submit the info to another page. Can someone tell me how to do this?

    This is the code I'm using. Normally, it would just print out the thank you text and the code to send it via e-mail. I need it to just forward the info to another page but I'm not sure how to do this.

    PHP Code:
    if (!isset($error)) {
     ?>
    //need to send it to another page here 
     <?
     
    }
     
    // this is the code in my form tag
    <form action="page2.php" method="post" enctype="multipart/form-data">
    Any help would be greatly appreciated.
    John Saunders

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JohnSaunders
    PHP Code:
    if (!isset($error)) {
      
    header("Location: http://www.site.com/page2.php");
     }

    // this is the code in my form tag
    <form action="page2.php" method="post" enctype="multipart/form-data"
    This should work

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean you need to pass the values form the form you processed over to the new page? Is the new page on your server?
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  4. #4
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I read too fast. yeah I think that is what he means

    You'll have to use a session for it, but maybe a little more information on what info needs to be passed?

  5. #5
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea, the only problem I see is if the page you are sending to is not on your server you won't be able to use a session for it. So more info is really required.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  6. #6
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The other page that I need to send the info to is on the same site/server but under a different sub-domain, in case that makes a difference.

    Thanks for your help.
    John Saunders

  7. #7
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, I am not sure. I have never tried it. To test what you can do is set the values into the $_SESSION array. So if you were storing their first name you would just do
    PHP Code:
    $_SESSION['fistname'] = $fistname
    then on the next page see if you can get it out of the session array
    PHP Code:
    echo ("The first name is: " $_SESSION['fistname']); 
    If it works let me know as I have never tried session across sub domains. I want to say it should work since they are on the server, but who knows?
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  8. #8
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I use "$_SESSION['fistname'] = $fistname; " where does the code go to tell it to go to the other page? What do I use for this?
    John Saunders

  9. #9
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, sorry...you still use the code that platinum was talking about by adding the header to the page.

    Code:
    header("Location: http://www.site.com/page2.php" )
    Just make sure you do that after you set the session variable.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  10. #10
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make sure you add session_start(); to the very top of each page as well

  11. #11
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK...I tried it out and the contact form page is located in an includes file that my main template page pulls. I put the code at the top of the contact includes page that does the error checking, then at the bottom it has the if there's no error, set the sessions and the header code.

    When I tried processing the form when it didn't produce any errors, it said "Cannot modify header information - headers already sent by Cannot modify header information - headers already sent by".

    I know this header code needs to be placed at the top of the script, but how do I do that when I do not want my entire template to check for errors on a contact form since there's many other pages involved.

    Is there some other way to do it besides using headers? Like maybe redirect or something?

    Any advice would be greatly appreciated.
    John Saunders

  12. #12
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, if you post the form to a processing page, then error check on that second page you should know if you want to forward or not before you output anything to the page. It is not so much it has to go at the top of the page, it just needs to be the first thing outputted to the page.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  13. #13
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rick,

    I added the code below to the top of the template page that I need to submit the form contents to, but I can't see or change anything above where I entered this in the template because it is encoded with Source Guardian.

    <?php
    session_start();
    echo ("The first name is: " . $_SESSION['firstname']);
    ?>

    This is the error I' m getting:

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started

    Is there anyway to get the data into the page besides using SESSIONS?
    John Saunders

  14. #14
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    depending on how much stuff it is you could try to put it in the url...but you run into the complicated process of verifying it all on the next page because users could screw with the url and remove some of the items or change the values.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  15. #15
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried changing the form method to "get" instead of "post" but it just kept posting to the same page and wasn't doing any error checking.
    John Saunders

  16. #16
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JohnSaunders
    I tried changing the form method to "get" instead of "post" but it just kept posting to the same page and wasn't doing any error checking.
    John,

    use output buffering to overcome the "headers already sent problem".
    You have to start the buffering on the very top of your page, before you sent ANYTHING at all.

    Here's how
    Code:
    /***
    * Begin output buffering.
    ***/
    ob_start();
    
    
    /***
    * Start a session
    ***/
    session_start();
    
    /***
    * Store your variables in a session file.
    * For example:
    ***/
    $_SESSION['firstname'] = $firstname;
    $_SESSION[lastname] = $lastname;
    
    /***
    * Redirect the user to second page
    ***/
    header("Location: .dirname($_SERVER['PHP_SELF']).&quot;/page2.php]http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/page2.php" );
    
    /***
    * On the second page
    ***/
    echo 'Thank you' . $_SESSION['firstname'] . ' ' . $_SESSION['lastname'];


    Hope this helps [img]images/smilies/wink.gif[/img]

  17. #17
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried using your code but unfortunately, I dont' think I can access the very top of the second PHP page to enter the ob_start(); code. The file is encoded using Zend and I cannot read it. The top of it looks like: "Zend 20001120011668243759x" so I can't even get to the top of the PHP script.

    Any other ideas how to get it to submit the data to the second page?
    John Saunders

  18. #18
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry John, but it is starting to sound like you might need to go back to whoever developed the existing app and encoded it to get this accomplished. The only other thing I can think of is you could write things out to a file I guess and then pull them out on the next page. As to getting to the next page, it might have to be manual link that has to be clicked.

    Sorry, guess I am running out of ideas, but hey I don't know everything by a long shot so maybe someone else has some ideas.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."


Bookmarks

Posting Permissions

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