-3

这是错误:

解析错误:语法错误,第 9 行 /home/idghosti/public_html/testground/mma/include/footer.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>";
    }
?>
4

3 回答 3

7

PHP 块不能跨越文件。看起来这就是你想要做的。

此外,如果您要打破块直接输出 HTML,我发现使用替代语法更具可读性。

于 2009-07-08T16:07:11.597 回答
2

您的代码有一些问题。我建议查看 IF 语句的一些教程以了解它们的工作原理。这是一个很好的网站供您执行此操作。

www.tizag.com

更新以反映评论:

取表单前的PHP代码块,放入toppart.php

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

------------------您的表单代码在这里------------------

把这个 PHP 代码块放在表单后面,放到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>";


} 


?>

您的新代码将如下所示:

include 'toppart.php';

/* Your Form Code Here */

include 'middlepart.php';

不幸的是,这个网站上的人会让你很难发布诸如此类的问题,所以在来这里寻求帮助之前做一些研究是很好的。当您无法找出问题时,PHP 编码可能会非常令人沮丧。我是来帮忙的。如果您还有任何问题,请随时发表评论。

祝你好运!!学习 PHP 是非常有益的。

于 2009-07-08T16:56:04.573 回答
1

有一个意外的'}',你在if(var){上面缺少了一个。

于 2009-07-08T16:13:51.257 回答