非特定错误,无明显原因
问题描述:
我是一名新手,正在通过“数据库驱动的网站”中的练习工作。非特定错误,无明显原因
下面的PHP提供了两个小时的思考和搜索未清理的错误。
当我调用的页面从浏览器中,我得到:
Parse error: syntax error, unexpected $end in /home/copydesign/www/listjokes.php on line 54
54行是:“”,这似乎是我的权利。
在BBedit中,第51行是一个空行,表示错误。第50行是“?>”,表示PHP解析结束。我讨厌问我是否应该能够为自己解决这个问题,但如果有人能帮助我,我会非常感激。
这里是整个页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The CopyDesign Internet Joke Database</title>
</head>
<body>
<?php if (isset($_GET['addjoke'])): // Visitor wants to add a joke
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Type a joke here:<br />
<textarea name="joketext" rows="10" cols="40">
</textarea></label><br />
</form>
<?php else: // Display default page
// Open a MySQL connection
$dbcnx = @mysql_connect('solas.phpwebhosting.com', 'copydesign', 'keylock');
// Select the joke database
if ([email protected]_select_db('ijdb')) {
exit('<p>Unable to connect to the joke database at this time.</p>');
}
?>
<p>CopyDesign's Internet Joke Database:</p>
<blockquote>
<?php
// Request the text of all the jokes
$result = @mysql_query('SELECT joketext FROM joke');
if (!result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>
</blockquote>
</body>
</html>
答
你忘了:
<?php endif; ?>
你有一个<? if(...): ?>
但没有结束现场。
答
您的if (isset($_GET['addjoke'])):
未关闭endif
。关闭它。
答
好像你没有关闭你的<?php if:
<?php else:
声明。 “意外的$结束”通常包括括号不匹配或代码块过早结束(并且解析器无法确定块的结尾)
你能在你的代码指明那些线? – jprofitt 2012-01-03 16:33:34