質問
これはエラーです:
解析エラー:構文エラー、/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>";
}
?>
解決
コードにはいくつかの問題があります。ステートメントがどのように機能するかを理解するために、いくつかのチュートリアルを見ることをお勧めします。これがあなたがこれを行うための良いウェブサイトです。
コメントを反映するための更新:
フォームの前に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';
残念ながら、このWebサイトの人々は、これらのような質問を投稿するのに苦労するので、助けを求めてここに来る前に研究をするのは良いことです。 PHPコーディングは、問題を把握できない場合、非常にイライラする可能性があります。私は助けるためにここにいます。質問がある場合は、自由にコメントを残してください。
幸運を祈ります!! PHPの学習は非常にやりがいがあります。
他のヒント
PHPブロックはファイルに及ぶことができません。それがあなたがやろうとしていることのようです。
また、HTMLを直接出力するためにブロックから脱出している場合、使用する方が読みやすいと思います。 代替構文.
予想外の '}'があります、あなたはありません if(var){
上に。
所属していません StackOverflow