警告:mysqli_fetch_row()期望参数1为mysqli_result,在C:\ wamp \ www \ widget_corp \ data_base.php中给出null

时间:2015-04-01 14:45:58

标签: php mysql connect

我正在尝试从MySQL表中选择数据,但是我收到了这样的警告:

  

注意:未定义的变量:导致第40行的C:\ wamp \ www \ widget_corp \ data_base.php

和这一个:

  

警告:mysqli_fetch_row()要求参数1为mysqli_result,在第40行的C:\ wamp \ www \ widget_corp \ data_base.php中给出null

这是我的代码:

   $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

    // Test if connection occured

    if (mysqli_connect_errno()){
        die ("Database connection failed: " . mysqli_connect_errno() . " (" . 
            mysqli_connect_errno() . ")"  );
    }

    // Perform database query
    $query = "SELECT * FROM subjects " ; 
    $resut = mysqli_query($connection, $query);

    // Test if there was a query error
    if (!$resut){
      die ("Database connection failed!");
    }

    // Use return data if any
    while ($row = mysqli_fetch_row($result)){
      //output data from each row
      var_dump($row);
      echo "<hr />";
    }

一切正常,直到while()。任何建议/解决方案?提前谢谢!

1 个答案:

答案 0 :(得分:1)

更加注意,你的语法错误:

$resut = mysqli_query($connection, $query);

将其更改为:

$result = mysqli_query($connection, $query);

并改为:

if (!$result){
      die ("Database connection failed!");
}