Mysqli_fetch_array()布尔错误

时间:2016-03-06 08:12:18

标签: php mysql mysqli phpmyadmin

第11行是while ($row = mysqli_fetch_array($select_user_profile_query)) {

警告:mysqli_fetch_array()要求参数1为mysqli_result,第11行的C:\ xampp \ htdocs \ renda \ admin \ profile.php中给出布尔值

if(isset($_SESSION['username'])) {

  $username = $_SESSION['username'];

  $query = "SELECT * users WHERE username ='{$username}' ";
  $select_user_profile_query = mysqli_query($connection, $query);

  while ($row = mysqli_fetch_array($select_user_profile_query)) {

$user_id = $row['user_id'];
$username = $row['username'];
$user_password = $row['user_password'];
$user_firstname = $row['user_firstname'];
$user_lastname = $row['user_lastname'];
$user_email = $row['user_email'];
$user_image = $row['user_image'];
$user_role = $row['user_role'];



}
}

谢谢!

1 个答案:

答案 0 :(得分:-1)

sql语句缺少from,也许您应该在尝试迭代记录集之前测试查询是否成功

<?php
    if(isset($_SESSION['username'])) {
        $username = $_SESSION['username'];

        $query = "SELECT * from `users` WHERE `username` ='{$username}' ";
        $select_user_profile_query = mysqli_query( $connection, $query );
        if($select_user_profile_query) {
            while ($row = mysqli_fetch_array($select_user_profile_query)) {
                $user_id = $row['user_id'];
                $username = $row['username'];
                $user_password = $row['user_password'];
                $user_firstname = $row['user_firstname'];
                $user_lastname = $row['user_lastname'];
                $user_email = $row['user_email'];
                $user_image = $row['user_image'];
                $user_role = $row['user_role'];
            }
        }
    }
?>