这样输出绝对不行,还要fetch操作的,楼主把代码改为:$db=new mysqli('localhost',$db_user,$db_pw,$db_name);
$edit=$db->query("select title,content from post where id=$id");
$edit=$edit->fetch_array(MYSQLI_ASSOC);//加上这个句子,查询资源
if (get_magic_quotes_gpc())
echo htmlspecialchars($edit['title']);
else
echo htmlspecialchars(stripslashes($edit['title'])); 

解决方案 »

  1.   


    global $db_user, $db_pw, $db_name;
    @$db=new mysqli('localhost',$db_user,$db_pw,$db_name);
    if (!$result)
    return false;
    return $db;
      

  2.   


    汗,不是一个也会要fetch操作的吧....
    感觉怪怪的
      

  3.   

    这个肯定的,在PHP都是这样调用的,query只是返回资源指针的
      

  4.   


    $result是????代码应该为:
    function connect_db($db_user, $db_pw, $db_name,)
    {
    global $db_user, $db_pw, $db_name;
    @$db=new mysqli('localhost',$db_user,$db_pw,$db_name);
    if (!$db)//这里改一下,明显是没定义的变量
    return false;
    else//这里最好也改改
    return $db;
    }
      

  5.   

    $handle=db_connect();
    $lim=$handle->query("select id from post order by id desc limit 0,1");<?
    while ($out=$result->fetch_assoc()) ========提示这里出错:Call to a member function fetch_assoc() on a non-object =======
    {?>

      <tr>
        <td align="center" width="45"><?php echo $out['id'];?></td>
        <td align="center" width="386"><a href="index.php?act=edit&id=<?php echo $out['id']; ?>"><?php echo htmlspecialchars($out['title']); ?></a></td>
        <td align="center" width="140"><?php echo htmlspecialchars($out['time']); ?></td>
      </tr>
    <?php } ?>我在出错那里无论用哪一个fetch都提示出错
    真是被搞晕了