I have one switch/toggle button that change the check status according to the data that i receive from databse.And if it's ON and if I click i want to save in a variable the value 0, and if i want to put ON i save 1.
The html code is this:
<div class="d5 col-md-2 col-xs-6">
<?php if($ligado=='0'){
?><input id='cmn-toggle-1' class='cmn-toggle cmn-toggle-round' onclick="$ligado=1"type='checkbox'unchecked >
<label for='cmn-toggle-1'></label>
<?php }
else{
?>
<input id='cmn-toggle-1' class='cmn-toggle cmn-toggle-round' onclick="$ligado=0" type='checkbox'checked >
<label for='cmn-toggle-1'></label>
<?php
}?>
</div>
This is inside of a form and when i POST i want to send the variable with the right value. I dont know if with onClick works, because i tested and i get nothing.
In my php i have this:
<?php
include_once 'dbconfig.php';
$descricao=$_GET['descricao'];
if(!empty($_POST['my_checkbox'])) {
$sql_query = "UPDATE alarme SET ligado=1 WHERE divisao=(SELECT id from divisao where descricao = '$descricao');";
$result_set=mysqli_query($link, $sql_query);
} else {
$sql_query = "UPDATE alarme SET ligado=0 WHERE divisao=(SELECT id from divisao where descricao = '$descricao');";
$result_set=mysqli_query($link, $sql_query);
}
header("Location:verdispositivo.php");
?>