title: Parsing and echoing SQL results in PHP
body: <p>I'm trying to write a simple PHP guestbook after following a few tutorials online. I am able to write to the database without any issues; however, when I try to parse through the existing comments and "echo" them back to the page, I am not seeing anything being displayed. </p>
  
  <p>Is there an obvious reason for this? </p>
  
  <p>(The code in question starts under <em>"Existing Comments:"</em>)</p>
  
  <pre><code>&lt;?php
  require_once('includes/config.inc.php');
  define('DB_GUEST','guestbook_db');
  
  // Connect
  $mysqli = @new mysqli(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD,DB_GUEST);
  
  // Check connection 
  if (mysqli_connect_errno()) { 
  printf("Unable to connect to database: %s", mysqli_connect_error()); 
  exit(); 
  } 
  
  // POST
  if($_SERVER['REQUEST_METHOD'] == 'POST') {
      $now = time();
      $name=($_POST['name']);
      $message =($_POST['message']);
  
  $sql = "insert into comments (name,message,timestamp) values  ('$name','$message','$now')";
  
      $result = $mysqli-&gt;query($sql) or die($mysqli-&gt;error.__LINE__);
  }
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title&gt;Guest Book&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h3&gt;Post A Comment:&lt;/h3&gt;
  &lt;form action="index.php" method="post"&gt;
     &lt;strong&gt;Name:&lt;/strong&gt;&lt;br/&gt; &lt;input type="text" name="name" /&gt;&lt;br/&gt;
     &lt;strong&gt;Comment:&lt;/strong&gt;&lt;br/&gt; &lt;textarea name="message" rows="5" cols="25"&gt;           
  &lt;textarea&gt;&lt;br/&gt;
  &lt;input type="submit" value="Go"&gt;
  &lt;/form&gt;
  
  &lt;h3&gt;Exisiting Comments:&lt;/h3&gt;
  
  &lt;?php
  $sql1 = "select * from guestbook_db.comments";
  $allPostsQuery = $mysqli-&gt;query($sql1) or die($mysqli-&gt;error.__LINE__);
  
  if(!mysql_fetch_rows($allPostsQuery)) {
      echo "No comments were found!";
  } else {
  while($row = mysql_fetch_assoc($allPostsQuery)) {
  echo "&lt;b&gt;Name:&lt;/b&gt; {$comment[1]} &lt;br/&gt;";
  echo "&lt;b&gt;Message:&lt;/b&gt; {$comment[2]} &lt;br/&gt;";
  echo "&lt;b&gt;Posted at:&lt;/b&gt; " .date("Y-d-m H:i:s",$comment[3]). " &lt;br/&gt;&lt;hr/&gt;";
      }
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>