PHP代码中的最后一行显示错误

时间:2014-01-15 16:53:16

标签: php

代码显示错误任何人都可以帮我解决问题

    $body .= 'Message: ' .echo "<h2>Your Input:</h2>"; echo "Name:".$name1; echo "<br>"; echo "Email:".$email1; echo "<br>";
 if(empty($contact)){echo("Contact:Didn't give anything.");} else{ echo "Contact:".$contact; } echo "<br>"; echo "Company:".$company; echo "<br>"; if(empty($aDoor)) { echo("You didn't select anything."); } else { $N = count($aDoor); 
 echo("You selected $N item(s): "); for($i=0; $i < $N; $i++){ echo($aDoor[$i] . " / "); } } echo "<br>"; 
 echo "website:".$website; echo "<br>"; echo "Projectdetail:".$projectdetail; echo "<br>"; if(empty($budget)){ 
 echo("budget:You didn't select anything."); } else { echo "budget:".$budget; } echo "<br>"; echo "budgetother:".$input_9_other;
 . "\n\n";

解析错误:语法错误,意外T_ECHO

4 个答案:

答案 0 :(得分:0)

你在这一行中得到了结论和回应:

$body .= 'Message: ' .echo "<h2>Your Input:</h2>";

您正在为变量赋值,因此删除echo并将两个字符串放在一起(追加它)。

  $body .= "Message: <h2>Your Input:</h2>";

试试这个:

$body .= 'Name: ' . $_POST['input_1'] . "\n\n";
$body .= 'Phone: ' . $_POST['input_11'] . "\n\n";
$body .= 'Email: ' . $_POST['input_12'] . "\n\n";
$body .= "Message: <h2>Your Input:</h2>";

答案 1 :(得分:0)

问题是echo这个词。这是一个将字符串输出到网页的命令,但您尝试将其包含在您正在构建的$body字符串中。

正确的修复取决于您想要实现的目标。您可能希望最初构建字符串(取出echo):

$body .= 'Name: ' . $_POST['input_1'] . "\n\n";
$body .= 'Phone: ' . $_POST['input_11'] . "\n\n";
$body .= 'Email: ' . $_POST['input_12'] . "\n\n";
$body .= 'Message: <h2>Your Input:</h2>';

之后,如果您愿意,可以输出整个字符串:

echo $body;

答案 2 :(得分:0)

您正在尝试连接字符串并在同一语句的中途回显它。

$body .= "<h2>Your Input:</h2>";
$body .= 'Name: ' . $_POST['input_1'] . "\n\n";
$body .= 'Phone: ' . $_POST['input_11'] . "\n\n";
$body .= 'Email: ' . $_POST['input_12'] . "\n\n";
$body .= 'Message: '; // I'm guessing you'll want another $_POST['input_?'] here
// At the end echo the whole message
echo $body;

更新问题

我无法判断您是否正在尝试回复文本或将其分配给变量,因此我猜对了它。

echo "<h2>Your Input:</h2>";
echo "Name: $name1";
echo "<br>Email: $email1";
echo "<br>" . (empty($contact) ? "Contact: Didn't give anything." : "Contact: $contact");
echo "<br>Company: $company";
if (empty($aDoor)) {
  echo "<br>You didn't select anything.";
} else {
  $N = count($aDoor);
  echo "<br>You selected $N item(s): ";
  for($i=0; $i < $N; $i++)
    echo $aDoor[$i] . " / ";
}
echo "<br>Website: $website";
echo "<br>Projectdetail: $projectdetail";
echo "<br>" . (empty($budget) ? "budget: You didn't select anything." : "budget: $budget");
echo "<br>budgetother: $input_9_other";

答案 3 :(得分:0)

Awlad Liton的回答是正确的,我只会添加不同的方法(依赖你的代码);示例应该解释为什么会出现语法错误。

$body .= 'Name: ' . $_POST['input_1'] . "\n\n";
$body .= 'Phone: ' . $_POST['input_11'] . "\n\n";
$body .= 'Email: ' . $_POST['input_12'] . "\n\n";
$body .= 'Message: ' . "<h2>Your Input:</h2>";

$body .= 'Name: ' . $_POST['input_1'] . "\n\n";
$body .= 'Phone: ' . $_POST['input_11'] . "\n\n";
$body .= 'Email: ' . $_POST['input_12'] . "\n\n";
$body .= 'Message: ';
echo  "<h2>Your Input:</h2>";