views:

134

answers:

3

This is the error

Parse error: syntax error, unexpected '}' in /home/idghosti/public_html/testground/mma/include/footer.php on line 9

This is the code:

<?php
    } else {
        error_reporting(0);

        if  (mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))

       //Message sent!
       //It the message that will be displayed when the user click the sumbit button
       //You can modify the text if you want
        echo nl2br("
        <div class=\"MsgSent\">
      <h1>Congratulations!!</h1>
      <p>Thank you <b>$name</b>, your message is sent!<br /> We will get back to you as soon as possible.</p>
     </div>
       ");

        else

        // Display error message if the message failed to send
        echo "
        <div class=\"MsgError\">
      <h1>Error!!</h1>
      <p>Sorry <b><?=$name;?></b>, your message failed to send. Try later!</p>
     </div>";
    }
?>
+7  A: 

PHP blocks cannot span files. It looks like that is what you are trying to do.

Also if you are breaking out of blocks to output HTML directly, I find it more readable to use the alternative syntax.

Tom Haigh
Please accept this as the answer, as it is extremely correct. ;)
anonymous coward
+1  A: 

There's an unexpected '}', you're missing an if(var){ on top.

ign
Can you please paste the full code so I might see the difference since im just startng to learn PHP
kwek-kwek
+2  A: 

There are a few things wrong with your code. I recommend looking at some tutorials for IF statements to understand how they work. Here is a good web site for you to do this.

www.tizag.com

UPDATE to reflect comments:

Take the PHP code block before the form and put it into toppart.php

<?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $self = $_SERVER['PHP_SELF']; ?>

------------------Your Form Code is here---------------------

Take this PHP code block after the form and put it into middlepart.php

<?php

} else {
    error_reporting(0);

    if  (mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) 

    //Message sent!
    //It the message that will be displayed when the user click the sumbit button
    //You can modify the text if you want
    echo nl2br("
    <div class=\"MsgSent\">
            <h1>Congratulations!!</h1>
            <p>Thank you <b>$name</b>, your message is sent!<br /> We will get back to you as soon as possible.</p>
    </div>
   ");


    else

    // Display error message if the message failed to send
    echo "
    <div class=\"MsgError\">
            <h1>Error!!</h1>
            <p>Sorry <b><?=$name;?></b>, your message failed to send. Try later!</p>
    </div>";


} 


?>

Your new code will look like the following:

include 'toppart.php';

/* Your Form Code Here */

include 'middlepart.php';

Unfortunately people on this web site will give you a hard time for posting questions such as these so it is good to do research before coming here for help. PHP coding can be very frustrating when you cannot figure out a problem. I am here to help. If you have any more questions feel free to leave a comment.

Best of Luck!! Learning PHP can be very rewarding.

Chris B.
+1 for a very good effort
anonymous coward
Thank you anonymous :)
Chris B.