警告:mysqli_fetch_assoc()期望参数1为mysqli_result,boolean

时间:2017-07-22 18:33:30

标签: php mysql

我的代码中有关于mysql_fetch_assoc()的警告,但我认为代码很好

    <?php
        $con = mysqli_connect("localhost","root","","profiles");
        $q = mysqli_query($con,"SELECT * FROM users");
        while($row = mysqli_fetch_assoc($q)){
            echo $row['username'];
            if($row['image'] == ""){
                echo "<img width='100' height='100' src='pictures/default.jpg' alt='Default Profile Pic'>";
            } else {
                echo "<img width='100' height='100' src='pictures/".$row['image']."' alt='Profile Pic'>";
            }
            echo "<br>";
        }
    ?>

2 个答案:

答案 0 :(得分:0)

这意味着您的查询失败。这里的明智之举是检查你的查询是否返回false,如下所示:

if(!$q){
  die("Error in query:". mysqli_error($con));
}

答案 1 :(得分:0)

首先,你必须检查错误。

<html>
<head>
   
<body>

<div class="parallax">
  <div class="parallax_group">
    <div class="parallax_layer parallax_layer--back">
      <p>Back Layer</p>
    </div>

    <div class="parallax_layer parallax_layer--base">
      <p>Base Layer</p>
    </div>

    <div class="parallax_layer parallax_layer--deep">
      <p>Deep Layer</p>
    </div>
  </div>

<div class="static_content">

</div>
</div>
   </body>
   </html>