连接数据文件~~conn.php
-----------------------
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
?>
-----------------------
bbs里面有message表 字段有~ id ,user ,title,content,lastdate 5个字段~(里面有2行数据了~~)
------------------------
求~~ 用代码读出mysql数据~
我学人家的老出错~~(你们帮我从写下吧!!!)
-------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<?php 
include("conn.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php
$sql="select * form message";
$query=mysql_query($sql);
while($sb=mysql_fetch_row($query)){
?>
<tr bgcolor="#eff3ff">
<td>标题:<? echo $sb[title]?> 用户:<? echo $sb[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容<? echo $sb[content]?>:</td>
</tr>
<?php 
}
?>
</table>
</body>
</html>

解决方案 »

  1.   

    很明显你的书写问题,例如:<td>标题:<? echo $sb[title]?> 用户:<? echo $sb[user]?></td>
    </tr>  你的分号在哪里,而且你在一个文件里用了两种书写格式,<? ?> <?php ?> 从基本功做起吧。
      

  2.   

    <? echo $sb[title]?> 改成<?php echo $sb[title]?>或 <?=$sb[title]?> 其他的一样改 
      

  3.   

    又 一个结贴率为0  下不为例哦  要不没有回答你的1.连接可能有问题:$conn = @ mysql_connect("localhost", "root", "") 前面不要加“@”它只是屏蔽错误 不是解决问题的根本。
    2.SQL语句不规划也是常出现错误的原因:$sql="select * form message";改为:
    $sql="select * form `message`";其中``是Esc键下的那个键。
    3.PHP语句错误 标题:<? echo $sb[title]?>  改为:标题:<?php echo $sb[title];?> 
    以上解决好了 就没有什么大错了 
      

  4.   

    你的代码中问题很多。
    select * form message中from写错啦。php代码应用<?php  ?>包含。mysql_fetch_row()返回的数组,其键名默认以数字顺序分配。
    应该用$sb[0],$sb[1],$sb[2].
      

  5.   

    <?php
    $sql="select * form message";
    $query=mysql_query($sql);
    while($sb=mysql_fetch_row($query)){
    ?>
    mysql_fetch_row 返回的是索引数组哦mysql_fetch_array 返回的才是关联数组