Show Check Marking in PHP and MySQL

0

I have a value of a checkbox saved in the database (table = way, field = active, values 1 = Active, 0 = Inactive, Boolean field), but when the form needs to be updated and opened, it does not show the check marked, always leaves it unmarked.

My code is as follows:

<div class="col-md-6 col-sm-6 col-xs-12 form-group has-feedback">
  <label class="control-label col-md-push-12 col-sm-12 col-xs-12">
                            <div class="checkbox">                               
                                <label>
                                    <?php
                                    $sqlprueba = mysqli_query($con, "SELECT * FROM way");
                                    $row = mysqli_fetch_assoc($sqlprueba);
                                    $check = $row['active'];
                                    if ($check == 1) {
                                        echo " checked";
                                    } else {
                                        echo "";
                                    }
                                    ?>
                                    <input type = "checkbox" name = "mod_active" value = "<?php echo $row['active']; ?>"<?php echo $check;
                                    ?>Activo <?php echo $row['active']; ?>

                                </label>
</div>
</div>
    
asked by Julián Cordoba 27.07.2018 в 22:39
source

1 answer

0
   $ccheck = '';  
    if ($check == 1) $ccheck = 'checked';
    ...
    <input type = "checkbox" name = "mod_active" value = "<?php echo $row['active']; ?>"<?php echo $ccheck...

(tip: forget about this horrible style of embedded code, it's not a good practice, when your code grows you'll be in trouble.) Greetings.)

    
answered by 28.07.2018 в 04:23