lundi 24 août 2020

read from multiple checkbox appearing in different divs with same value

i have written bootstrap code for checkboxes with label appear side by side based on screen size they are divided into different divs. when i try to upload the values of checked box into database using php and mysql im getting error that foreach isnt passed an array and when i checked the array has only the last checked item and not the items checked before them

<div class="form-row">
                <div class="col-6 col-sm-3">
                    <div class="form-check"><input class="form-check-input" type="checkbox" name="features[]" value="wifi"><label class="form-check-label" for="wifi">wifi</label></div>
                </div>
                <div class="col-6 col-sm-3">
                    <div class="form-check"><input class="form-check-input" type="checkbox" name="features[]" value="hotwater"><label class="form-check-label" for="hotwater">Hot Water</label></div>
                </div>
                <div class="col-6 col-sm-3">
                    <div class="form-check"><input class="form-check-input" type="checkbox" name="features[]" value="ac"><label class="form-check-label" for="ac">A.C</label></div>
                </div>
                <div class="col-6 col-sm-3">
                    <div class="form-check"><input class="form-check-input" type="checkbox" name="features[]" value="food" style="background-color: #ffffff;"><label class="form-check-label" for="food">Food</label></div>
                </div>
            </div>

and php code is $features = $_POST['features'];

$feat="";
foreach($features as $feat1){
    //write if condition for inserting icons into database if $feat1==wifi{$feat=<i>fas fa wifi wifi</i>}
    $feat.=$feat1.",";
}

when i try to read $features it only has the last feature. how can i get all the checked values? thanks in advance




Aucun commentaire:

Enregistrer un commentaire