Checkbox selected in PHP

0

I am looking for SQL Server checkboxes to be pre-selected according to the data contained inside and I have not been able to do it. I tried everything, here is the last code I have executed.

 <div class="col-md-12">
                        <div class="form-group">
                            <label for="hongosbacterias">8. Hongos/Bacterias/Virus: </label>
                            <div class="checkbox">
                            <?php
                                $conn = connectDB();
                                $sql = "select honBacVir from formulario";
                                $result = query($conn, $sql);
                                while ($arreglo = mssql_fetch_array($result)) {
                                    for($i = 0; $i <= 4; $i++){
                                    $sel = "";
                                    if ($_POST['hongosbacterias'] == $arreglo['honBacVir']) $sel = "checked";
                                    ?>
                                   <label>
                                        <input type="checkbox" name="hongosbacterias[]" value="Esclerotinia" <?= $sel ?>>
                                        Esclerotinia
                                      </label>
                                      <label>
                                        <input type="checkbox" name="hongosbacterias[]" value="Fusarium" <?= $sel ?>>
                                        Fusarium
                                      </label>
                                      <label>
                                        <input type="checkbox" name="hongosbacterias[]" value="Mildiu" <?= $sel ?>>
                                        Mildiu
                                      </label>
                                      <label>
                                        <input type="checkbox" name="hongosbacterias[]" value="Botritis" <?= $sel ?>>
                                        Botritis
                                      </label>
                                      <label>
                                        <input type="checkbox" name="hongosbacterias[]" value="otros" <?= $sel ?>>
                                        Otros
                                      </label>
                                <?php }
                                }
                                 ?>

                            </div>
                        </div>
                    </div>

And so they are saving themselves in the database:

I'm using normal PHP.

    
asked by Roberto Caamaño Riquelme 31.05.2016 в 16:48
source

0 answers