I have this loop for list rows, what I want to do is return to base 1 or 0 (1 check, 0 uncheck) to that row that is listed. I manage to do this without the WHILE function, but in while function it won't work.
<?php
$interval = $conn->query("SELECT ID,Vrsta_segmenta, Active FROM `msa_segmenti`");
if ($interval->num_rows > 0) {
while($row = $interval->fetch_array()) {
$checked = $row["Active"];
?>
<form name="update" method="POST" action="msa_pauze_admin.php" class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"><?php echo $row["Vrsta_segmenta"];?></label>
<div class="col-md-9 col-sm-9 col-xs-12">
<div class="">
<label>
<input type="checkbox" name="check" value="<?php echo $row["Active"];?>" class="js-switch"
<?php
if ($checked == '1') { ?> checked
<?php
} else if ($checked == '0') ""
?>
</label>
</div>
</div>
</div>
<?php }} ?>
<button type="submit" class="btn btn-success" value="Save">Save</button>
Now i need to return value to the db when i click save button. I know i need to check click state so i try this but did not work:
if (isset($_POST["check"])) {
$check_value == '1';
$interval_check_save = "UPDATE `msa_segmenti` SET `Active` = '".$check_value."' WHERE `ID` = '".$id."'";
$mysqli->query($interval_check_save);
} else {
$check_value == '0';
$interval_check_save = "UPDATE `msa_segmenti` SET `Active` = '".$check_value."' WHERE `ID` = '".$id."'";
$mysqli->query($interval_check_save);
}