日期:2014-05-17  浏览次数:20558 次

求鉴定错误,实在找不出来
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link href="css.css" rel="stylesheet" type="text/css" />
<title>无标题文档</title>
</head>

<body>


<div id="total">
 <div id="top">
  <div class="top_title">
  <div class="login_title">
  <ul>
  <li><a href="login.php">登录</li>
<li><a href="regiser.php">注册</li>
<li>链接</li>
  </ul>
  </div>
  <div class="top_beijing">
  </div>
  </div>

 </div>
 <div id="middle">
 <?php
  $conn=mysql_connect("localhost","root","5200");
if(!$conn){
die ("连接失败".mysql_error());
}
mysql_select_db("blog",$conn) or die(mysql_error());

mysql_query("set names utf8");
$sql="select * from article";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){


echo "<div class="article">"; 41
echo "<div class="article_title"><p>$row['article_title']</p></div>";
echo "<div class="article_body"><p>$row['article_body']</p></div>";
echo "</div>";


}

   
 
 ?>
 

</div>
</div>
</body>
</html>

显示错误
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\wamp1\www\blog\index.php on line 41
明明我写的是;却还是这个错误。。求解释

------解决方案--------------------
echo "<div class="article">"; 41
这错误没看出来? echo "<div class="到这儿就算字符串完了,后面本应该就是分号,但这儿却是字符串article。
还不明白?正确的做法是对字符串中的双引号用\"转义
以下写法都算正确:
PHP code
// 转义双引号
echo "<div class=\"article\">";
// 改用单引号,防止与字符串内的双引号冲突
echo '<div class="article">';
// 方便一点的,改用
echo <<<html
    <div class="article">
html;

------解决方案--------------------
echo "<div class="article">"; //41
echo "<div class="article_title"><p>$row['article_title']</p></div>";
echo "<div class="article_body"><p>$row['article_body']</p></div>";
echo "</div>";

改为
echo <<< HTML
<div class="article">
<div class="article_title"><p>$row[article_title]</p></div>
<div class="article_body"><p>$row[article_body]</p></div>
</div>
HTML;

既简单又清晰
切记!最后的 HTML; 要顶格