title: Get and store id from database to different table based on user search input
body: <p>I have multiple dynamic textboxes where users input license plate no. I'm trying to retrieve the id corresponding to the license plate # inputted by the user from the database but I'm unable to get it. I want to store the <strong>license plate #'s <em>id</em></strong> that's already in the database to a different table and not the license plate no itself, but It always returns null.</p>
  
  <p>Thanks in advance.</p>
  
  <h2>search.js</h2>
  
  <pre><code>function firetruckAddingTextBoxes() {
  var NumOfText = $("#NumOfTextBoxes2").val();
  $('.NewlyCreatedSelectBoxes2').empty();
  var txtBox = "";
  
  for (i = 0; i &lt; NumOfText; i++) {
      txtBox += '&lt;input type="text" name="firetruck[]" class="search" placeholder="License Plate No" required/&gt;&lt;br&gt;';
  }
  $('.NewlyCreatedSelectBoxes2').append(txtBox);
  
  
  
  $(".NewlyCreatedSelectBoxes2").on("keyup", ".search", function () {
      var search_term = $(this).val();
  
      $('#search_results2').html('Searching database...');
  
      if (search_term !== '') {
          $.post('php/firetruck_search.php', { search_term: search_term }, function (data) {
              $('#search_results2').html(data);
          });
      } else {
          $('#search_results2').html('Not Found');
      }
  
  });
  return false;
  
  }
  </code></pre>
  
  <hr>
  
  <h2>search.php</h2>
  
  <pre><code>&lt;?php
  require('connectdb.php'); 
  
  if(isset($_POST['search_term']))
  {
      $search_term = mysql_real_escape_string(htmlentities($_POST['search_term']));
  
      if(!empty($search_term))
      {
          $search = mysql_query("SELECT `fireTruckID`, `licensePlateNo` FROM `firetruckinfo` WHERE `licensePlateNo` LIKE '%$search_term%'");
          $result_count = mysql_num_rows($search);
  
          $suffix = ($result_count != 1) ? 's' : '';
          echo '&lt;p&gt;Your search for ', $search_term, ' returned ', $result_count, ' result', $suffix, '&lt;/p&gt;';
  
          while($results_row = mysql_fetch_assoc($search))
          {
              echo '&lt;p&gt;', $results_row['licensePlateNo'], '&lt;/p&gt;';
          }
      }
  }
  ?&gt;
  </code></pre>
  
  <hr>
  
  <h2>occurrence.php</h2>
  
  <pre><code>$firetrucks = $_POST['firetruck'];
          foreach($firetrucks as $firetruck):
              $vehicleID = mysql_query("SELECT `fireTruckID` FROM `firetruckinfo` WHERE `licensePlateNo`='$firetruck'");
              $row2 = mysql_fetch_assoc($vehicleID);
  
              $query3 = "INSERT INTO `truckonscene`(`FireTruckInfo_fireTruckID`, `IncidenceOfFire_incidentID`)
                     VALUES(
                     '".mysql_real_escape_string($row2['fireTruckID'])."',
                     '".mysql_real_escape_string($incidentid)."')";
  
              mysql_query($query3) or die(mysql_error());
          endforeach;
  </code></pre>