title: Failing to connect/get results from database using PHP
body: <p>I am trying to connect to the database and display the information on the page.  </p>
  
  <p>Here is the model</p>
  
  <pre><code>&lt;?php
  // model for the totals of the wreath orders
  require_once("dbconnect.php");
  
  // connect to database and check errors
  @ $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  
  $connection_error = $dbc-&gt;connect_error;
  if ($connection_error != null) {
    echo "&lt;p&gt;Error connectiong to database: $connection_error&lt;/p&gt;";
    exit();
  }
  ?&gt;
  </code></pre>
  
  <p>Here is the code from the page where I construct the string and try to connect and display the data on the screen.  </p>
  
  <pre><code>&lt;?php
  require_once('model.php');
  
  $query = "SELECT * FROM people WHERE";
  
  if  (isset ($_POST['fname'])) {
      $fname = $_POST['fname'];
      $query = $query . " fname = '" . $fname . "' AND";
  }
  if (isset ($_POST['lname'])) {
      $lname = $_POST['lname'];
      $query = $query . " lname = '" . $lname . "' AND";
  }
  
  if (isset ($_POST['age'])) {
      $age = $_POST['age'];
      $query = $query . " age = '" . $age . "' AND";
  }
  
  if (isset ($_POST['city'])) {
      $city = $_POST['city'];
      $query = $query . " city = '" . $city . "' AND";
  }
  
  $query = rtrim($query, " AND");
  include('header.php');
  ?&gt;
  &lt;div id="header"&gt;
  &lt;h1&gt;&lt;strong&gt;This is the information you requested&lt;/h1&gt;&lt;/strong&gt;
  &lt;/div&gt;
  &lt;div id="main"&gt;
  &lt;?php
  $results = $dbc-&gt;query($query);
  $row_count = $result-&gt;num_rows;
  
  for ($i = 0; $i &lt; $row_count; $i++) :
          $product = $result-&gt;fetch_assoc();
      echo $product['fname'] . " | " . $product['lname'] . " | " . $product['age'] . " | " . $product['city'] . ' &lt;br /&gt;';
  endfor;
  ?&gt;
  &lt;/div&gt;
  &lt;?php
  include('footer.php');
  </code></pre>
  
  <p>Here is the error I get</p>
  
  <pre><code>Notice: Undefined variable: result in C:\Program Files\wamp\www\testwebpage\Model\getinformation.php on line 34
  
  Trying to get property of non-object in C:\Program Files\wamp\www\testwebpage\Model\getinformation.php on line 34
  </code></pre>
  
  <p>I can say I'm pretty new to this and am just not sure what would be wrong with the code.  </p>