title: Drop-Down-Menu to display all records from a query into a table AJAX and PHP
body: <p>How do I display all the records from a query that I executed into a table when I choose a <code>id</code> from my <code>car_types</code> drop-down-menu.</p>
  
  <p>Here is the code I had done so far, I keep getting an error whenever I run my SQL query 
  <code>$carResult = mysqli_query($link, $carQuery)</code>, how do I solve it or is my method of doing wrong?</p>
  
  <p>Error: <code>Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Cars\carShop.php on line 54</code></p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  $link = mysqli_connect('localhost', 'root', '', 'db_car');
  
  if (!$link) {
      die(mysqli_error($link));
  }
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Car Shop&lt;/title&gt;
          &lt;script type="text/javascript" src="script/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              $(document).ready(function() {
                  $("#type").change(function() {
                      $.ajax({
                          type: "GET",
                          url: "getCars.php",
                          data: "type_id=" + $(this).find(":selected").val(),
                          cache: false,
  
                          success: function(msg){
                              query = $.parseJSON(msg);
                              $('#query').html(query);
                          }
                      });
                  });
                  $("#type").trigger('change');
              });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;select id="type" name="type"&gt;
                  &lt;?php
                  $query = "SELECT * FROM car_types";
                  $result = mysqli_query($link, $query) or die(mysqli_error());
                  while ($row = mysqli_fetch_assoc($result)) {
                      echo "&lt;option value ='" . $row['id'] . "'&gt;" . $row['type_name'] . "&lt;/option&gt;";
                  }
                  ?&gt;
          &lt;/select&gt;&lt;br&gt;
  
          &lt;table border="1"&gt;
              &lt;tr&gt;
                  &lt;th&gt;Car ID&lt;/th&gt;
                  &lt;th&gt;Name&lt;/th&gt;
                  &lt;th&gt;Price&lt;/th&gt;
              &lt;/tr&gt;
  
              &lt;?php
              $carQuery = " &lt;div id='query'&gt;&lt;/div&gt;";
              echo $carQuery;
              $carResult = mysqli_query($link, $carQuery) or die(mysqli_error());
              while($row = mysqli_fetch_assoc($carResult)) { ?&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;?php echo $row['id'];?&gt;&lt;td&gt;
                      &lt;td&gt;&lt;?php echo $row['name'];?&gt;&lt;td&gt;
                      &lt;td&gt;&lt;?php echo $row['price'];?&gt;&lt;td&gt;
                  &lt;/tr&gt;
              &lt;?php } ?&gt;
  
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>getCars.php</p>
  
  <pre><code>&lt;?php
  $link = mysqli_connect('localhost', 'root', '', 'db_car');
  
  if (!$link) {
      die(mysqli_error($link));
  }
  
  $typeId = $_GET['type_id'];
  
  $query = "SELECT * FROM cars WHERE type_id = $typeId";
  
  
  echo json_encode($query);
  ?&gt;
  </code></pre>