这是出现问题的代码: <?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"> </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
$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"> </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
$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);
无语了。哥们,别做程序员了。
echo $row->title; echo "</td><td> " ; echo $row->content;
echo "</td> <td height=30> </td> </tr>";
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函数不熟,并且有较大的逻辑错误。
还有就是多看看php手册。