单击的复选框将显示另一个输入字段,如何将其放入数据库?

I have a working code where if I select multiple checkboxes, it will be saved in the database in separate rows (it is required). Also, I have a working code where if it checks a certain checkbox, another input field will show. Now, how do I save the checkbox value along the other input field that comes with it in the database?

This is the form:

<form class="form-horizontal form-label-left" name = "documentRequest" enctype="multipart/form-data" role="form" method="post" novalidate>

<div class = "second">

<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"> Document Request(s) <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">

<input type="checkbox" name="docs[]" id="doc1" value="Certificate of Residency" /> Certificate of Residency
<br/>
<div class = "col-xs-3">
    <input name="d1" class="form-control col-md-7 col-xs-12" required="required" type="number">
</div>

<div class = "clearfix"></div>

<input type="checkbox" name="docs[]" id="doc2" value="Barangay Clearance"  /> Barangay Clearance                                                    
<br />
<div class = "col-xs-3">
    <input name="d2" class="form-control col-md-7 col-xs-12" required="required" type="number">
</div>

    <div class = "clearfix></div>
</form>

This is my php code (this works; it saves multiple checkbox values):

<?php
include 'config.php';

if (isset($_POST['documentRequest']))
{

 $chkbox = $_POST['docs'];

 $i = 0;

 foreach($chkbox as $chk1)  
   {  
       $query = mysqli_query($conn, "INSERT INTO document(typeOfDoc) VALUES ('$chk1');"); 
   }  
 echo "Checkbox value is successfully submitted.";
 } ?>

This is the picture of the form: enter image description here

Can you all please help me? How do I save this? Thank you.

    Try this

 <?php
 include 'config.php';

    if (isset($_POST['documentRequest']))
     {

       $chkbox = $_POST['docs'];

         $i = 0;

         foreach($chkbox as $chk1)  
           {
                if($chk1=='Certificate of Residency') 
                {
                  $chek_val=$_POST['d1'];
                }
                else if($chk1=='Barangay Clearance') 
                {
                  $chek_val=$_POST['d2'];
                }

               $query = mysqli_query($conn, "INSERT INTO document(typeOfDoc,docval) VALUES ('$chk1','$chek_val');"); 
           }  
         echo "Checkbox value is successfully submitted.";
         } ?