从数据库创建输出时,我不断收到错误消息。
错误消息:“解析错误:语法错误,第26行的XXXXXXXXX.php意外$结束。”
下面使用的代码。
<?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 successfully\n";
mysql_close($conn);
?>
有没有人对为什么这不起作用有任何建议?谢谢。
答案 0 :(得分:1)
您的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 successfully\n";
mysql_close($conn);
?>
建议:使用支持匹配和正确语法突出显示的好IDE,它会使这样的错误非常明显。
编辑:正如评论中建议的@ Rizier123,您不应该收到意外的变量$end
错误,请向我们展示connectDB.php
的内容,毕竟可能还有更多。