title: PHP and MYSQLI Error, Call to a member function query() on a non-object
body: <p>I'm getting the Call to a member function query() on a non-object when I try to call my function.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>function add_profile() {
  
      $hostname = "localhost";
      $dbusername = "username";
      $dbname = "dbname";
      $dbpassword = "password";
      $link = mysqli_connect($hostname, $dbusername, $dbpassword, $dbname); 
      if (!$link) { 
      die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); 
      } 
  
      $sql = "INSERT INTO payment_profiles(id, client_id) VALUES ( '','$profile_id')"; 
  
      $result = $mysqli-&gt;query($sql);
      if (!result) 
      { 
      echo 'Error: ', $mysqli-&gt;error;
      }
  }
  
  add_profile();
  </code></pre>
  
  <p>It says my error is on the line: <code>$result = $mysqli-&gt;query($sql);</code></p>
  
  <p>I'm assuming I'm not calling something properly. Thanks in advance for any help</p>