另一个 PHP 语法错误

发布于 2024-07-26 21:58:26 字数 1473 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮倦 2024-08-02 21:58:26

PHP 块不能跨越文件。 看起来这就是您正在尝试做的事情。

另外,如果您打破块直接输出 HTML,我发现使用 替代语法

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.

尹雨沫 2024-08-02 21:58:26

您的代码有一些问题。 我建议查看一些有关 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 是非常有益的。

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.

最终幸福 2024-08-02 21:58:26

有一个意外的“}”,您缺少顶部的 if(var){

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文