分析错误:语法错误,意外的$end



从数据库创建输出时,我不断收到错误消息。

错误消息:"分析错误:语法错误,第26行XXXXXXXX.php中出现意外$end。"

下面是正在使用的代码。

<?php
    require('connectDB.php');
    if ($connection) {
      echo "Connected to database!";
    } else {
          die("Connection failed: " . mysqli_connect_error());
    $query = "SELECT title, description, body, created FROM diary_post";
    $result = mysql_query($query);
    $retval = mysql_query( $query, $connection );
    if(! $retval )
    {
      die('Could not get data: ' . mysql_error());
    }
    while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
    {
        echo "title :{$row['title']}  <br> ".
             "description : {$row['description']} <br> ".
             "body : {$row['body']} <br> ".
             "created : {$row['created']} <br> ".
             "--------------------------------<br>";
    } 
    echo "Fetched data successfullyn";
    mysql_close($conn);
    ?> 

有人对为什么这不起作用有什么建议吗?非常感谢。

您的else子句缺少右花括号:

<?php
require('connectDB.php');
if ($connection) {
  echo "Connected to database!";
} else {
      die("Connection failed: " . mysqli_connect_error());
} // This should be here
$query = "SELECT title, description, body, created FROM diary_post";
//$result = mysql_query($query);
$retval = mysql_query( $query, $connection );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "title :{$row['title']}  <br> ".
         "description : {$row['description']} <br> ".
         "body : {$row['body']} <br> ".
         "created : {$row['created']} <br> ".
         "--------------------------------<br>";
} 
echo "Fetched data successfullyn";
mysql_close($conn);
?> 

建议:使用一个好的IDE,使用括号匹配和适当的语法高亮显示,这样的错误会很明显。

编辑:正如@Rizier123在评论中建议的那样,你不应该得到一个意外的变量$end错误,请向我们展示connectDB.php的内容,毕竟可能还有更多。

相关内容

  • 没有找到相关文章

最新更新