title: PHP Notice: Trying to get property of non-object
body: <p>I've been trying for a few days now to fix this part of my PHP code, but nothing seems to be working.</p>
  
  <p>I'm basically a super-newb. Pretty much last week I decided to try and make a blog from scratch using PHP. This requires that I learn PHP. So, by following tutorials and reading sites like w3schools, I've slowly been learning applicable PHP. </p>
  
  <p>Anyway, here is the part of my code I'm working on:</p>
  
  <pre><code>$query = $db-&gt;prepare("SELECT post_id, title, body, date_posted, category
                         FROM posts INNER JOIN categories ON
                         categories.category_id=posts.category_id ORDER BY
                         post_id desc limit $start, $per_page");
  $query-&gt;execute();
  $query-&gt;bind_result($post_id, $title, $body, $date_posted, $category);
  
  $author = $db-&gt;prepare("SELECT username FROM posts INNER JOIN user ON
                              user.user_id=posts.user_id");
  print_r( $author-&gt;error );
  $author-&gt;execute();
  $author-&gt;bind_result($username);
  </code></pre>
  
  <p>Let me explain. I have 3 database tables: posts, categories, and user. Most post information is in "posts," including category_id and user_id, but not the actual names of the category and user. I get those from the other two tables. $db uses mysqli.</p>
  
  <p>The $query part of the above code works perfectly fine. The $author prepare line is where I'm having an issue. I wrote that line based on the $query prepare line that works. </p>
  
  <p>But when I run the code, I get "Notice: Trying to get property of non-object." This then leads to $author->execute() not working and producing the error: "Fatal error: Call to a member function execute() on a non-object."</p>
  
  <p>So again, since I'm a mega-newb, I assume the fix is something really simple that probably has to do with my ignorance of PHP. Does anyone have any idea or suggestions? Thanks in advance for the help.</p>