I'm trying to update my database tinyint to 1 when the checkbox is checked and to 0 when the checkbox is unchecked. My Javascript/Ajax code is:
<script>
function emailNextWithAddress(chk,address) {
var nextEmail, inside_where;
if(chk.checked === true){
$.ajax({
url: "marca_enviado.php",
type: "get",
data: address,
success: function(){
nextEmail = document.createElement('input');
nextEmail.id = address;
nextEmail.value = address;
nextEmail.type = 'text';
nextEmail.name = 'email[]';
nextEmail.className = 'insemail';
nextEmail.style.display = 'inline-block';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
},
error: function(){
console.log("Erro!");
}
});
} else {
$.ajax({
url: "desmarca_enviado.php",
type: "get",
data: address,
success: function(){
inside_where = document.getElementById(address);
inside_where.parentNode.removeChild(inside_where);
},
error: function(){
console.log("Erro!");
}
});
}
return false;
}
</script>
And the php (marca_enviado.php) code which tries to update my database tinyint is:
<?php
include_once 'dbh.php';
$address = $_GET['address'];
$updateEnviado = "UPDATE escolas SET Enviado = 1 WHERE id= 'address' ";
$result = mysqli_query($conn , $updateEnviado);
?>
$updateEnviado = "UPDATE escolas SET Enviado = 1 WHERE id= 'address' "There are multiple things wrong here, you are always updating to 1 and you are always updating a record havingid= 'address'which probably does not existdata: address,what isaddress?