title: Fatal error: Call to a member function fetch_assoc() on a non-object
body: <p>i have an error in my code while using function fetch_assoc</p>
  
  <pre><code>&lt;?php
      include_once('functions.php'); 
  
      $book_selected=$_POST['book_selected']; 
      $database = new mysqli('127.0.0.1', 'user', 'user', 'library'); 
      $query = 'SELECT * FROM book WHERE title=\'' . $book_selected . '\''; 
      $result_set = $database-&gt;query($query); 
      $row = $result_set-&gt;fetch_assoc(); 
      var_dump($row);
      $query = 'UPDATE poll_result SET num_poll = num_poll + 1 WHERE id='. $row['id']; 
      $database-&gt;query($query); 
      redirect('show_polling.php');
  ?&gt;
  </code></pre>
  
  <p>and I got the error : </p>
  
  <blockquote>
    <p>Fatal error: Call to a member function fetch_assoc() on a non-object </p>
  </blockquote>
  
  <p>I don't know how to fix it.</p>
  
  <p>Thanks for advice</p>