doupu7651 2015-09-08 07:53
浏览 65
已采纳

致命错误:在第17行的......中的非对象上调用成员函数fetch_assoc()[重复]

This question already has an answer here:

After migrating from localhost to webserver I'm getting this error. Maybe it could be because of the PHP version on webserver (PHP 5.2). Any ideas?

<?php
$servername ="";
$username ="uran";
$password ="";
$dbname ="";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM answer WHERE topic_key='$id'";
$result = $conn->query($sql);
 // output data of each row
while($row = $result->fetch_assoc()) {
    echo "<strong>Príspevok č.:</strong> " . $row["id"]. "<br>"."     <strong>Napísal:</strong> " 
    . $row["name"]. "<br>". $row["topic"]."<br>" . $row["reg_date"]."<br>"."  <br><br>";
}

$conn->close();
 ?>
</div>
  • 写回答

1条回答 默认 最新

  • doubi2145 2015-09-08 08:00
    关注

    I think that your query fails to that $conn->query($sql) will return FALSE (see mysqli::query).

    Please add the following code to your code to get the error message:

    if (!$result) {
        printf("Error: %s
    ", $conn->error);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料