动态文本框并将其保存在mysql中

I'm trying to add my qualification details in dynamic text boxes and store it in mysql, but it is not working. I can add the details and can store the details for the first time, but in case of edit, I can't add new data. Meanwhile I have two tables, first one formdata which has all data except qualification, second one is qualification table with only qualification details which has foreign key ref from formdata. Somebody help please.

Edit form qualification table

Edit code:

<?php


     $query3=mysqli_query($conn, "select * from qualification where user_id='$id'");
                      while ($record = $query3->fetch_assoc())
                      {
                         $resultset[] = $record;
                      }
                      $rows = mysqli_affected_rows($conn);
                      for ($i=0;$i<$rows;$i++)
                      {
                        ?>

                        <input type="hidden" name="id[]" value="<?php echo $resultset["$i"]['id']; ?>" />
                        <tr id="textboxgroup<?php echo $i ?>">
                        <td>
                             <input type="text" name="instname[]" id="iname" class="group" value="<?php echo $resultset["$i"]['instname']; ?>"/>
                        </td>
                        <td>
                             <input type="text" name="year[]" id="year" class="group" value="<?php echo $resultset["$i"]['year']; ?>"/>
                        </td>
                        <td>
                             <input type="text" name="percentage[]" id="percentage" class="group" value="<?php echo $resultset["$i"]['percentage']; ?>"/>
                        </td>
                        <td>
                             <input type="button" name="add" id="add" value="+" onclick="addrow();"/>
                             <input type="button" name="remove" id="remove" value="-" onclick="remove(this);"/>
                        </td>
                      </tr>
                      <?php
                      }
                    ?>
                    <tr id="new"></tr>
                   </table>
                  <input type= "hidden" id="user_id" name="user_id" value="<?php echo $query2['user_id']; ?>"/>
                  <input type="submit" class="update" name="update" value="Update"/>
                  <input TYPE="button" class="back" value="Back" onclick="window.location.href='display1.php';"/> 
      </fieldset>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>
    function addrow(){
            var tr = $('#textboxgroup0').clone();
            tr.find('.group').val('');
            tr.insertBefore('#new');
    }
    function remove(obj)
         {
              var parentDiv = $(obj).parent().parent();
              if(parentDiv.attr('id') !== 'textboxgroup0') {
              parentDiv.remove();
              }
              if(parentDiv.attr('id') == 'textboxgroup0') {
              var tr = $('#textboxgroup0');
              tr.find('.group').val(''); }
         }
    </script>

Update Code:

 $instname = $_POST['instname'];
           $year = $_POST['year'];
           $percentage = $_POST['percentage'];
           $max = (count($_POST["year"]));
           $id1=$_POST['id'];
           for ($i=0; $i<$max; $i++)
           {
           $instname1 = $instname[$i];
           $year1 = $year[$i];
           $percentage1 = $percentage[$i];
           $id2=$id1[$i];
           $sql2= "INSERT INTO qualification(id, user_id, instname, year, percentage) VALUES ($id2, $id, $instname1, $year1, $percentage1) ON DUPLICATE KEY UPDATE user_id='$id', instname='$instname1', year='$year1', percentage='$percentage1' ";
           $qual = mysqli_query($conn,$sql2);
           }