I'm getting this error, can't get rid of it. Google won't help me. 
I don't really understand, what is really wrong here: "Trying to get property 'num_rows' of non-object" 
The thing is I want to send value as company_name not company_id.
And if I change company_id to company_name, then textarea gives me that error. (i want to change to company_name, coz to save value to db)
Maybe someone can explain me. I'm new in this thing.
while ($row = $result->fetch_assoc()) {
                      echo '<option value="' . $row['company_id'] . '">' . $row['company_name'] . '</option>';
                    }
( ! ) Notice: Trying to get property 'num_rows' of non-object in C:\wamp64\www\Baigiamasis\ajaxData.php on line 12
Call Stack
#TimeMemoryFunctionLocation
10.0004407600{main}(  )...\ajaxData.php:0
This is ajaxData.php file:
    <?php 
// Include the database config file 
include_once 'dbConfig.php'; 
if(!empty($_POST["company_id"])){ 
    // Fetch state data based on the specific country 
    $query = "SELECT * FROM receiver WHERE company_id = ".$_POST['company_id']." AND status = 1 ORDER BY company_name ASC"; 
    $result = $db->query($query); 
    // Generate HTML of state options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select</option>'; 
        while($row = $result->fetch_assoc()){  
            echo $row['company_address'];
            // echo ''.$row['company_address'].''; 
        } 
    } 
}
?>
This is the ajax script:
<script>
  $(document).ready(function() {
    $('#companyName').on('change', function() {
      var companyID = "";
      companyID = $(this).val();
      if (companyID) {
        $.ajax({
          type: 'POST',
          url: 'ajaxData.php',
          data: 'company_id=' + companyID,
          success: function(html) {
            $('#address').html(html);
            $('#city').html('<option value="">Select first</option>');
          }
        });
      } else {
        $('#address').html('<option value="">Select first</option>');
        $('#city').html('<option value="">Select first</option>');
      }
    });
  });
</script>
And the dropdown part:
           <?php
           include_once 'dbConfig.php';
           $query = "SELECT * FROM receiver WHERE status = 1 ORDER BY company_name ASC";
           $result = $db->query($query);
           ?>                
        <select type="text" class="form-control" name="companyName" id="companyName" autocomplete="off" >
          <option value="">Select Receiver</option>
          <?php
          if ($result->num_rows > 0) {
            while ($row = $result->fetch_assoc()) {
              echo '<option value="' . $row['company_name'] . '">' . $row['company_name'] . '</option>';
            }
          } else {
            echo '<option value="">Company not available</option>';
          }
          ?>
        </select>
        <textarea class="form-control" rows="3" name="address" id="address" placeholder="Address"></textarea>
 
    