【问题标题】:Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/dwilson2/public_html/WBG410/reviews.php on line 20 [closed]解析错误:语法错误,意外的 '}',期待 ',' 或 ';'在第 20 行的 /home/dwilson2/public_html/WBG410/reviews.php [关闭]
【发布时间】:2015-04-22 21:31:53
【问题描述】:

我需要一些帮助来查找此代码的问题。第 20 行就在 $row 评论下方。我已经和其他人一起查看了这段代码,但我们不知道该怎么做。该代码应该最终显示三个值,并且由于此错误,我无法测试该代码。我在第 20 行添加了注释,以便于查找。

<?php
$servername = "localhost";
$username = "dwilson2_410wrt";
$password = "3275626s";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT name, id, comment FROM review";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " $row["comment"]
} // this is line 20
}


$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>My Gaming Products Site</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

有人知道代码有什么问题吗?我知道它一定遗漏了什么,但我不知道是什么。就像我之前说的,第 20 行有一个注释,以便于查找。如果我需要添加更多代码,我会尝试这样做。

【问题讨论】:

  • 语法错误离题
  • 提示,它不在第 20 行。不要相信 PHP 所说的一切
  • 提示:还不到一个完整的。
  • 实际的错误安德鲁,我可以叫你安德鲁,是}之前的那行
  • 机器错误 - 第 20 行。人为错误 - 第 19 行

标签: php parse-error


【解决方案1】:

在这一行(第 19 行)

echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["comment"]

您需要以分号结束该行,否则 PHP 将假定它只是 echo 的一部分之后的所有内容。

【讨论】:

    猜你喜欢
    • 2014-04-28
    • 1970-01-01
    • 2012-06-13
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 2015-03-03
    相关资源
    最近更新 更多