At first I was able to save values into the table called "tbl_spareparts" but when i added a foreign key it doesnt save anymore.
tbl_spareparts(unit_id) is referenced to tbl_unitdescription(id).
code is for dynamic fields where you can add more input boxes or remove them.
here is my insert code:
     <?php
  $connect = mysqli_connect("localhost", "root", "", "incidentreport");
   if(isset($_POST['submit_data'])) {
   $description = $_POST['description'];
   $qty = $_POST['qty'];
                                          
   foreach ($description as $key => $value) {
   $save = "INSERT INTO tbl_spareparts(unit_id,description,qty) VALUES ('','".$value."', '".$qty[$key]."')";
    $query =    mysqli_query($connect, $save);
      }
     }
    ?>
 
     
    