title: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result,
body: <p>I have this warning but I have not found what causes this error, please guys can you light me?
  The error is in line 58 ---> $data = mysqli_fetch_assoc($result) or die();{
  I searched for a while but can't find how i tacle that error called. </p>
  
  <p>"Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:.... on line 58"</p>
  
  <pre><code>&lt;?php
  require_once('connect.php');
  
  $user_id = 0;
  
  function print_header($title="Header") { ?&gt;
  
  &lt;title&gt;PDS&lt;/title&gt;
  
  
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;?php 
  
  
  global $user_id;
  if (logged_in()){
      $session_user_id = $_COOKIE['pds-usn'];
      $user_data = user_data($session_user_id, 'id', 'name', 'hashed_pw', 'email', 'last_name', 'email', 'site', 'level', 'joined', 'posts', 'type');
      echo $user_data['name'];
      echo 'U bent ingelogd als '.$_COOKIE['pds-usn'].'. &lt;a href="login.php?logout=1"&gt;Uitloggen&lt;/a&gt;';
  }   else {
      echo "U bent niet ingelogd. &lt;a href='login.php'&gt;Login&lt;/a&gt; of &lt;a href='register.php'&gt;registreer&lt;/a&gt;.";
  }
  
  
  
  ?&gt;
  
  
  &lt;?php }
  
  
  function print_footer() { ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php }
  
  function user_data($user_id) {
  
  include('connect.php');
  
  $data = array();
  $user_id = (int)$user_id;
  
  $func_num_args = func_num_args();
  $func_get_args = func_get_args();
  
  if ($func_num_args &gt; 0) {
      unset($func_get_args[0]);
  
      $fields = '`' . implode('`, `', $func_get_args) . '`';
      $sql = "SELECT $fields FROM users WHERE id = $user_id";
      $result = mysqli_query($connect, $sql);
      $data = mysqli_fetch_assoc($result) or die();
      return $data;
  
  }   
  }else {
      return false;
  }
  
  ?&gt;
  </code></pre>
  
  <p>Connect.php:</p>
  
  <pre><code>&lt;?php
  
  $connect = mysqli_connect("localhost", "root", "password") or die(header('Location: errorpage.php?error=2'));
  mysqli_select_db($connect, "pds_news_feed") or die(header('Location: errorpage.php?error=3'));
  ?&gt;
  </code></pre>