【问题标题】:Parse error: syntax error, unexpected end of file, expecting '`' [duplicate]解析错误:语法错误,文件意外结束,期待'`' [重复]
【发布时间】:2020-01-12 20:08:34
【问题描述】:

我收到此错误: 解析错误:语法错误,文件意外结束,期待 '`'

这里是代码

<?php 

//create connection
$conn = new mysqli("localhost", "root", "","database");

//check connection
if($conn->connect_error)    
    die("Connection failed " . $conn->connect_error);

    $sql = "SELECT * FROM Book";
    $result = $conn->query($sql);

if ($result->num_rows > 0) 
  {
    echo "<table><tr> <th>ISBN</th> <th>Writer</th> <th>Title</th> <th>Pages</th><th>Year Published</th> <th>Publisher</th> </tr>";
    while($row = $result->fetch_assoc())    
    {
      echo "<tr><td>"  . $row[ISBN]. "</td><td>". $row[Writer] . "</td>" ;
      echo "<td> " . $row[Title] . "</td><td>" . $row[Number_of_pages] . "</td><td>" . $row[Year] . "</td><td>" . $row[Publishing_house] . "</td></tr>";
    }
    echo "</table>";

  } 
else 
{
    echo "0 results";
}

$conn->close();
?>

short_open_tag 开启 我什至使用在线 php 语法检查器进行了检查,它说没有语法错误。

【问题讨论】:

  • 代码高亮显示问题。
  • ` $result = $conn->query($sql); 行从多余的` 开始
  • 是的,我刚刚看到了。这么小

标签: php html mysql sql


【解决方案1】:

你在这一行多了一个“`”:

`   $result = $conn->query($sql);

只需删除反引号:

   $result = $conn->query($sql);

【讨论】:

    【解决方案2】:

    从这一行中删除反引号(`):

    `   $result = $conn->query($sql);
    

    顺便说一句,我绝对建议您在一个不错的代码编辑器中编写代码,并使用适当的语法高亮显示。

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      相关资源
      最近更新 更多