PHP checklist get ID and value and store it
<p>So I have a form to add a new item to database with a  checkbox as follows</p>

<p><a href="https://i.stack.imgur.com/fEtzG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fEtzG.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/OIGVN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OIGVN.png" alt="enter image description here"></a></p>

<p>So my difficulty is the checkbox. I can easily enough create the array for all items checked but I need an ID for them along with it. I've tried to think of many ways and searched a lot but I just can't think of a way to get the ID in a way that is then useable to me along with the name of the feature (checklist). Since I have to get each feature item and add it to the table houses_has_features.</p>

<pre><code>&lt;?php
$title = 'Add a new house';
require_once 'header.php';
require_once 'nav.php';
require_once 'mysqli-con.php';

$conn = new MYSQLI($hn, $un, $pw, $db);

// If house name and type is set then add them into the database
if( !empty($_POST['h_name']) &amp;&amp; !empty($_POST['h_type']) ) {
    $house_name = $conn-&gt;real_escape_string($_POST['h_name']);
    $house_type = $conn-&gt;real_escape_string($_POST['h_type']);

    //show names added
    echo '&lt;b&gt;House name: &lt;/b&gt;'.$house_name . '&lt;br&gt;&lt;b&gt; House type:&lt;/b&gt;  ' . $house_type;

    $query = "INSERT INTO `house_names` (`id`, `name`) VALUES (NULL, '$house_name')";
    $result = $conn-&gt;query($query);
    if (!$result) die ("&lt;b class='text-danger'&gt;&lt;p&gt;Insert failed ERRROR: " . $conn-&gt;error. "&lt;/p&gt;");

    global $house_name_id;
    $house_name_id = $conn-&gt;insert_id;
    $query = "INSERT INTO `house_types` VALUES ('$house_name_id', '$house_type')";
    $result = $conn-&gt;query($query);
    if (!$result) die ("&lt;b class='text-danger'&gt;&lt;p&gt;Insert failed ERRROR: " . $conn-&gt;error. "&lt;/p&gt;");
    } else {
    global $house_name_id;
    $house_name_id= NULL;
    }



//Start container for page content
echo '&lt;div class="container"&gt;';

//Display an error message if house name is filled in but not house type
if ( !empty($_POST['h_name']) &amp;&amp; empty($_POST['h_type']) || empty($_POST['h_name']) &amp;&amp; !empty($_POST['h_type']) ) {
    echo "&lt;p class='error-text'&gt;* Please fill in both the house name and house type *&lt;/p&gt;";
}




$query_feat = $conn-&gt;query('SELECT * FROM features');
$rows = $query_feat-&gt;num_rows;


$features_list  = $_POST['check_list'];
$feature_id = $_POST['feature_id'];
//display checked boxes.
if(isset($_POST['check_list'])) {
    for ($i=0; $i&lt;sizeof($features_list); $i++){

        //echo '&lt;br&gt;House name id:' . $house_name_id . '&lt;br&gt; $_POST[] = ' . "$features_list[]";
        print_r($features_list); echo '&lt;br&gt;';
        print_r($feature_id);
    }
}




// Add house form
echo &lt;&lt;&lt;_END


    &lt;h1&gt;Add a house&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="container"&gt;
    &lt;form action="add.php" method="post"&gt;
        &lt;p&gt;House Name: &lt;input type="text" name="h_name"&gt;&lt;/p&gt;
        &lt;p&gt;House type: &lt;input type="text" name="h_type"&gt;&lt;/p&gt;
        &lt;b&gt;features:&lt;/b&gt; 
        &lt;ul class="list-group"&gt;
_END;
        for ($c = 0 ; $c &lt; $rows ; ++$c){

        $query_feat-&gt;data_seek($c);
        $feat = $query_feat-&gt;fetch_array(MYSQLI_NUM);


        echo '&lt;li&gt;&lt;input type="checkbox" name="check_list[]" value="' .$feat[1]. '"&gt;'.$feat[1].'&lt;/li&gt;';

}


echo &lt;&lt;&lt;_END
        &lt;ul&gt;
        &lt;input class="btn-primary" type="submit" value="Submit"&gt;
    &lt;/form&gt;
&lt;/div&gt;

_END;



require_once 'footer.php';
</code></pre>

<p>I'm really lost on this one any help would be greatly appreciated :)</p>