php errors in code on submit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stealthmode666
    New Member
    • Nov 2008
    • 21

    php errors in code on submit

    Not sure how to show this in tags so I have attached .txt file
    need urgent help as this form i've made is live.
    I used spry widgets to check the form as it's filled in by uploading the .js and .css files to do this. I use this code to extract the data and send it to an email but this Warning and notices happen if all the form is not filled in.
    If all fields are filled it goes through and loads and displays the thank-you page.
    The email is still sent with what-ever fields are filled in but the user gets a page of notices and the warning about the header.
    Sorry if I seem to be going round in circles here.
    But trying to learn as fast as possible and managed to work out the sprys in minutes even if I don't understand some of the .js script that is writen by dreamweaver, so i am trying.

    I only posted this here as this forum has real help as opposed to some that will look and laugh at beginners, so thanks all.
    I got help already with this the other day in here with the isset tags
    Attached Files
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by stealthmode666

    [..]
    People do not like to download attachments in case they're malicious. To post code with formatting, just write [code] .. code goes here .. [/code]

    Also, please include the errors and any information that could be helpful.

    Thanks,
    Markus.

    Comment

    • stealthmode666
      New Member
      • Nov 2008
      • 21

      #3
      I've done wrong again, just read through the entire forum rules, i have had previous help already relating to the code, sorry for starting a slightly different thread but still relating to my problem

      Comment

      • stealthmode666
        New Member
        • Nov 2008
        • 21

        #4
        [code=php]I have done this file as I'm not sure how to post it with-out just pasting it in the message window.

        This is the warning message I get and I have shown the two lines in my script it refers to.

        Warning: Cannot modify header information - headers already sent by (output started at

        E:\domains\r\.. ...com\user\htd ocs\r.....\sfor m.php:180) in E:\domains\r\.. ...com\user\htd ocs\r.....\sfor m.php

        on line 193


        This is the code I use to extract the fields to the email address:


        // original old script
        #$to = $_REQUEST['sendto'] ;
        #$from = $_REQUEST['Email'] ;
        #$name = $_REQUEST['Member_Name'] ;
        $headers = "From: $from";
        $subject = "Members Data ....com";

        //changed to now use this as needed it not to show NOTICE:index messages of blank fields but it still does.
        $to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" );
        $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
        $name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ;
        $headers = "From: $from";
        $subject = "Members Data From RedSquareFinanc e.com";

        $fields = array();
        $fields{"Member _Name"} = "Members Name";
        etc..etc..

        //body of email to send to person with the extracted form data.
        [line 180] $body = "Thank-you.....:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s:

        %s\n",$b,$_REQU EST[$a]); }

        //headers and autoreply to show the user his data has been sent
        $headers2 = "From: someone@somewhe re.com";
        $subject2 = "Thank-you for filling....";
        $autoreply = "Somebody will get back to you ....";


        //I don't need these if or else statements as form is checked via .js file now
        if($from == '') {print "You have..Email";}
        else {
        if($name == '') {print "You have.. First Name, ...go back and try again";}
        else {
        $send = mail($to, $subject, $body, $headers);
        $send2 = mail($from, $subject2, $autoreply, $headers2);
        if($send)
        [Line 193] {header( "Location: http://www...com/r.../thankyou.html" );}
        else
        {print "We encountered ...webmaster@.. com";
        }
        }
        }
        ?>
        [/code]

        Thanks for that hope this is right

        Comment

        • stealthmode666
          New Member
          • Nov 2008
          • 21

          #5
          okay, maybe too much in my post now

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            to me it looks like php thinks of the sprintf() command as start of output.

            regards

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              OK. Line 180, you output data to the browser and then after you try to use the header() function. You cannot do that. The header() function needs to send headers to the browser, and if you've already sent data to the browser (180) then the header() function will cause a fatal error.

              You need to work around this.

              -- nevermind: dorm got there before me.

              Comment

              • stealthmode666
                New Member
                • Nov 2008
                • 21

                #8
                Err, see how one look and you know, but I haven't got a clue how to do this.
                I'm still learning basic fuctions and tags.
                I use this scipt to do the same work on a simple form with about three fields and it works, but that doesn't mean by this that it's right. All this was a tutorial I followed and now I have landed myself in trouble. Not homework or assignment so I will try to read up on what to do but i need this working urgently. Thanks for the help in at least pointing me in the right direction.
                Last edited by stealthmode666; Dec 3 '08, 02:27 PM. Reason: typo errors in spelling

                Comment

                • stealthmode666
                  New Member
                  • Nov 2008
                  • 21

                  #9
                  Okay, trying quickly to understand, the header then is already sent as in (output started at E:...) which means the html has been written to the browser.
                  I am also using .php to send a header. So how can I code this to get .php to send a header before any html is output?
                  Am on the right tracks here?

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    Originally posted by stealthmode666
                    [code=php]//I don't need these if or else statements as form is checked via .js file now[/code]
                    never rely on javascript validation alone, users (i.e. I) often have javascript turned off. so always do server side validation!

                    regards

                    Comment

                    • stealthmode666
                      New Member
                      • Nov 2008
                      • 21

                      #11
                      I do server-side .js validation for the reason of the client having it turned of.
                      I will learn as time goes by to use php to validate but at the moment it was easier to make .js file and load to server to check the form as user fills it in.
                      After doing server-side validation the form works perfectly now as no undefined fields are sent.
                      Thanks all for help on this. next problem I will start a new thread as different problem to this but still php

                      Comment

                      Working...