<?php
$result = mysql_query("select * from gbook where id=".$id,$conn);
if(!$rs = mysql_fetch_array($result)){
echo '没有这条记录。<a href="./">返回</a>';
}else{
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0" bgcolor="#0000ff">
  <tr>
    <th colspan="2" bgcolor="#FFFFFF">留言标题<?php echo $rs['title']?></th>
  </tr>
  <tr>
    <th bgcolor="#ffffff" width="20%" align="right">姓名:</th>
    <td bgcolor="#ffffff"><?php echo $rs['username']?></td>
  </tr>
  <tr>
    <th bgcolor="#ffffff" width="20%" align="right">时间:</th>
    <td bgcolor="#ffffff"><?php echo date('Y-m-d H-i-s',$rs['addtime'])?></td>
  </tr>
  <tr>
    <th bgcolor="#ffffff" width="20%" align="right">内容:</th>
    <td bgcolor="#ffffff"><?php echo $rs['content']?></td>
  </tr>
</table>
<?php
}
?>

解决方案 »

  1.   


    <?php
    $result = mysql_query("select * from gbook where id=".$id,$conn);
    $num = mysql_num_rows($result);
    if($num<1)
    {
    echo '没有这条记录。<a href="./">返回</a>';
    exit();
    }
    ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#0000ff">
    <?php 
    while($rs = mysql_fetch_array($result)){
    ?>
      <tr>
      <th colspan="2" bgcolor="#FFFFFF">留言标题<?php echo $rs['title']?></th>
      </tr>
      <tr>
      <th bgcolor="#ffffff" width="20%" align="right">姓名:</th>
      <td bgcolor="#ffffff"><?php echo $rs['username']?></td>
      </tr>
      <tr>
      <th bgcolor="#ffffff" width="20%" align="right">时间:</th>
      <td bgcolor="#ffffff"><?php echo date('Y-m-d H-i-s',$rs['addtime'])?></td>
      </tr>
      <tr>
      <th bgcolor="#ffffff" width="20%" align="right">内容:</th>
      <td bgcolor="#ffffff"><?php echo $rs['content']?></td>
      </tr>
    <?php
    }
    ?>
    </table>
      

  2.   


    <?$result = mysql_query("select * from gbook where id=".$id,$conn);
    if(!$rs = mysql_fetch_array($result)){
    echo '没有这条记录。<a href="./">返回</a>';
    }else{
    ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#0000ff">
      <tr>
      <th colspan="2" bgcolor="#FFFFFF">留言标题<?php echo $rs['title'];?></th>
      </tr>
      <tr>
      <th bgcolor="#ffffff" width="20%" align="right">姓名:</th>
      <td bgcolor="#ffffff"><?php echo $rs['username'];?></td>
      </tr>
      <tr>
      <th bgcolor="#ffffff" width="20%" align="right">时间:</th>
      <td bgcolor="#ffffff"><?php echo date('Y-m-d H-i-s',$rs['addtime']);?></td>
      </tr>
      <tr>
      <th bgcolor="#ffffff" width="20%" align="right">内容:</th>
      <td bgcolor="#ffffff"><?php echo $rs['content'];?></td>
      </tr>
    </table>
    <?php
    }?>
    你的逗号都漏了
      

  3.   

    $result = mysql_query("select * from gbook where id=".$id,$conn);你得说明,$id,$conn来源吧?是有效的
      

  4.   


    这是我的全部代码:
    <?php
    error_reporting(E_ALL & ~E_NOTICE); 
    session_start();
    if(function_exists('date_default_timezone_set')) date_default_timezone_set('Etc/GMT-8');//时区 define('G_DBHOST','localhost');
    define('G_DBUSER','root');
    define('G_DBPWD','root');
    define('G_DBNAME','gbook');
    define('CHARSET','utf-8');
    header("Content-Type:text/html;Charset=".CHARSET);

    $conn = mysql_connect(G_DBHOST,G_DBUSER,G_DBPWD) or die("数据库密码错误");
    mysql_select_db(G_DBNAME) or die("选择数据库失败,请预先建立数据库");
    $charset = (CHARSET=='utf-8') ? 'utf8' : CHARSET;
    mysql_query("SET NAMES '$charset'" , $conn);
    mysql_query("SET sql_mode ''" , $conn);

    $id = is_numeric($_GET['id']) ? $_GET['id'] : 0;
    if($_SERVER['REQUEST_METHOD']=='POST' && $_POST['con_form']=='gbook1'){
    $username = isset($_POST['username']) ? $_POST['username'] : '';
    $title = isset($_POST['title']) ? $_POST['title'] : '';
    $content = isset($_POST['content']) ? $_POST['content'] : '';
    if($title=='' || !(strlen($content)>=2 && strlen($content)<=2000)){
    echo '<script language="javascript">alert("标题不能为空或内容必须要2——2000字符之间");location="info.php";</script>';
    exit;
    }
    mysql_query("insert into gbook1 (title,username,addtime,content) values($title,$username,".time().",'$content')",$conn);
    echo '<script language="javascript">alert("提交成功!");location="info.php";</script>';
    exit;
    }
    ?><!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>内容页</title>
    </head><body>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC">
      <tr>
        <th height="50">欢迎光临-------------mysite!</th>
      </tr>
    </table>
    <!-------导航条结束----------------><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="10"></td>
      </tr>
    </table><!-----------内容开始---------------------------------->
    <?php
    $result = mysql_query("select * from gbook where id=".$id,$conn);
    $num = mysql_num_rows($result);
    if($num<1){
    echo '没有这条记录。<a href="./">返回</a>';
    exit;
    }
    ?>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0" bgcolor="#0000ff">
    <?php
    while($rs = mysql_fetch_array($result)){
    ?>
      <tr>
        <th colspan="2" bgcolor="#FFFFFF">留言标题<?php echo $rs['title']?></th>
      </tr>
      <tr>
        <th bgcolor="#ffffff" width="20%" align="right">姓名:</th>
        <td bgcolor="#ffffff"><?php echo $rs['username']?></td>
      </tr>
      <tr>
        <th bgcolor="#ffffff" width="20%" align="right">时间:</th>
        <td bgcolor="#ffffff"><?php echo date('Y-m-d H-i-s',$rs['addtime'])?></td>
      </tr>
      <tr>
        <th bgcolor="#ffffff" width="20%" align="right">内容:</th>
        <td bgcolor="#ffffff"><?php echo $rs['content']?></td>
      </tr>
    </table>
    <?php
    }
    ?>
    <!----------内容结束----------------------------------><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="30"></td>
      </tr>
    </table><!-------信息提交开始---------------->
    <table width="100%"  border="0" cellspacing="1" cellpadding="0" bgcolor="#ff0000">
      <form name="form1" method="post" action="" onsubmit="return Validator.Validate(this,3);">
      <tr>
        <th colspan="2" bgcolor="#ffffff">我要留言</th>
      </tr>
      <tr>
        <th width="20%" align="center" bgcolor="#ffffff">姓名:</th>
        <td bgcolor="#ffffff"><input type="text" name="username" /></td>
      </tr>
      <tr>
        <th width="20%" align="center" bgcolor="#ffffff">*标题:</th>
        <td bgcolor="#ffffff"><input type="text" name="title" /></td>
      </tr>
      <tr>
        <th width="20%" align="center" bgcolor="#ffffff">*内容:</th>
        <td bgcolor="#ffffff"><textarea name="content" cols="50" rows="8"></textarea></td>
      </tr>
      <tr>
        <td align="center" bgcolor="#ffffff" colspan="2">
    <input type="submit" value="提交内容">
    <input type="hidden" name="con_form" value="post_gbook1">
    </td>
      </tr>
      </form>
    </table>
    <!-------信息提交结束----------------></body>
    </html>
      

  5.   

    LZ的程序中分号是可以省略的,因为有?>跟着,,但是的确是完整的语句,加上貌似更规范
    error_reporting(E_ALL & ~E_WARNING);
    改成
    error_reporting(E_ALL);$result = mysql_query("select * from gbook where id=".$id,$conn);
    var_dump($id, $conn);exit;//打印看看?同时检测下数据库表名是gbook?因为当前你的代码,表错了,也不会任何提示
    而且,我发现,你插入时候,表名是gbook1 
      

  6.   


    var_dump($id, $conn);exit;
    这个打出来是:int(0) resource(2) of type (mysql link) 
      

  7.   

    代码书写习惯,把你页面中所有<?php echo $rs['username']?>这个写法的换成"><?php echo $rs['username'];?>   PHP中最后的个;可以不写,自动会匹配的,但你的全没写。
      

  8.   

    你现在能直接看gbook这个表的数据吗?
    看里面有没有内容,然后取一个id
    把$result = mysql_query("select * from gbook where id=".$id,$conn);中的$id直接换成数据表中的值,试下!
      

  9.   


    这不是问题吗?int0,,,id没有传参还有,我前面说了,你的分号是没问题的,但是你插入操作,和查询操作不是一个表名。还有你结贴率太低
      

  10.   


    $result = mysql_query("select * from gbook where id="."1",$conn);
    你说的是这样吗?不行啊
      

  11.   

    $result = mysql_query("select * from gbook where id=".$id) or die(mysql_error());
      

  12.   

    php代码和html代码最好分开 你这样写实在太 乱了 习惯要养成 这是个简单的 留言,发帖,回复问题 
      

  13.   

    哪里不行就哪里测试打印 die(内容或者变量参数);
      

  14.   

    mysql_query("insert into gbook1 (title,username,addtime,content) ;
     你往gbook1里面插数据,从gbook取?
      

  15.   

    谢谢大伙们的热情帮助,我解决了,我做的是两个页面,list.php
    info.php当直接打开info.php时 id 没有传值,只有从list.php点击进去,这样就实现整个一条数据的读取了。