How can I do that through toggle I update my database? I have the toggle below:
Forthis,I'mdoingitthisway:
<divclass="onoff">
<strong>Desabilitar notificações por e-mail:</strong>
<input type="checkbox" class="toggle" id="onoff">
<label for="onoff"></label>
<input type="hidden" name="Avisar" id="campo1" value="0">
</div>
......
<script type='text/javascript'>
//<![CDATA[
window.onload=function(){
var onoff = document.getElementById('onoff');
onoff.addEventListener('change', function() {
estado = this.checked ? 'S' : 'N';
var campo = document.getElementById("campo1").value = estado;
$.ajax({
url: 'notificacoes.php',
type: 'post',
data: {
estado: this.checked,
campo: campo
}
}).done(function(msg) {
});
});
}//]]>
///////////////////
</script>
And PHP:
....
$idUsuarios = $_SESSION["IdUsuarios"];
$status = $_POST["estado"];
....
mysqli_query($this->conexao,"UPDATE tabela SET Notificacoes = '".$status."' WHERE IdUsuario = '".$idUsuarios."';
Only you are not updating. The problem is in Jquery , because PHP is working correctly.