这是出现问题的代码: <?php
$conn=mysql_connect("localhost","root","614510")or die("数据库服务器连接错误".mysql_error());
mysql_select_db("message",$conn)or die("数据库访问错误".mysql_error());
mysql_query("set names gb2312");
$keyword=isset($_POST['txt_keyword'])?$_POST['txt_keyword']:'';
$sql=mysql_query("select *from aaa where title like  '%keyword%' or content  like  '%keyword%'");
$row=mysql_fetch_object($sql);
if(!$row){
echo  "<font color='red'>您搜索的信息不存在,请使用类似的关键字进行检索!</font>";
}
do{
?>
                        <tr>
                          <td><?php echo $row->title;?></td>
                          <td><?php echo $row->content;?></td>
                          <td height="30">&nbsp;</td>
                        </tr>
                        <?php
}while($row=mysql_fetch_object($sql));
mysql_free_result($sql);
mysql_close($conn);
?>
出现的错误提示是:Notice: Trying to get property of non-object in E:\php\phpnow\htdocs\talking\message-select.php on line 98
Notice: Trying to get property of non-object in E:\php\phpnow\htdocs\talking\message-select.php on line 99

解决方案 »

  1.   

    $sql=mysql_query("select *from aaa where title like  '%keyword%' or content  like  '%keyword%'");
    $row=mysql_fetch_object($sql); =======>
    $sql=mysql_query("select *from aaa where title like  '%keyword%' or content  like  '%keyword%'",$conn);
    $row=mysql_fetch_object($sql); 
      

  2.   

    问题出在do...while中。在do中的$row->xxx等属性不存在
      

  3.   

    恩,mysql_query函数的语法也错了。
    无语了。哥们,别做程序员了。
      

  4.   

    3楼的:不好意思,我再请教一下,刚才你说的do中的$row->xxx等属性不存在,是说把我的表单由$row->title改成$row->txt_title,还是说我那儿写的<?php echo $row->title;?> <?php echo $row->content;?> 没有用?
      

  5.   

     $row-> 这里应该写字段的名字
      

  6.   

    select * from aaa...... 这里这么写。 
      

  7.   

    <?php echo $row->title;?> <?php echo $row->content;?> title和content就是字段名,我试过了,还是不行,但是我把<?php echo $row->title;?> <?php echo $row->content;?>删除了之后,就不出现错误提示了,那样的话,是不是就找不到要查找的内容啦?
      

  8.   

     echo "<tr><td>";
     echo $row->title; echo "</td><td> " ; echo $row->content;
    echo "</td> <td height=30>&nbsp</td> </tr>";
      

  9.   

    $keyword=isset($_POST['txt_keyword'])?$_POST['txt_keyword']:)'';这个是不是有问题 
      

  10.   

    在PHP中要想插入HTML代码必须是ECHO输出的!
      

  11.   

    $keyword=isset($_POST['txt_keyword'])?$_POST['txt_keyword']:)'';这条语句的作用是搜索关键字,搜索不到的时候返回为空……应该没有错吧?
      

  12.   

    改成9楼说的方法还是不行啊,在查询页面直接就出现了"; echo $row->title; echo "  " ; echo $row->content; echo "  这些代码……
      

  13.   

    我的意思是说
    if(!$row)
    那么你do那里就有警告了
    Notice: Trying to get property of non-object in E:\php\phpnow\htdocs\talking\message-select.php on line 98 
    Notice: Trying to get property of non-object in E:\php\phpnow\htdocs\talking\message-select.php on line 99
    正是这个
    而你前面的函数调用错了,导致后面没有结果,也就暴露了你下面的错误。
    你现在的问题是php函数不熟,并且有较大的逻辑错误。
      

  14.   

    楼主如果要继续做,那么就好好学学程序基本的东西,这个和语言没关系。
    还有就是多看看php手册。