jquery:
$("input[name='flag']").on('change', function() {
event.preventDefault();
var tablerow = $(this).closest('tr');
var id = $(this).attr('id');
var flagvalue;
if($(this).prop('checked') == true) {
tablerow.css({'background-color':'rgba(175,0,0,0.2)'});
flagvalue = 1;
}
else {
tablerow.css({'background-color':'rgba(175,0,0,0)'});
flagvalue = 0;
}
alert(flagvalue);
$.ajax({
url: "../php/insert.php",
method: "get",
data: {"flagvalue":flagvalue,"id":id},
dataType: "text"
success:function(data)
{
$('#ohmygod').html(data); //it doesnt echo anything from here :(
}
});
});
php:
$insertMessage = "";
$bendera = filter_input(INPUT_POST, 'flagvalue', FILTER_SANITIZE_SPECIAL_CHARS);
$id = $_POST['id'];
if(!empty($bendera)) { //also doesn't work if change it to isset
$insertMessage = "Reached the php part";
$updateflag = "UPDATE sintok SET flag='$bendera' WHERE id='$id'";
mysqli_query($connection, $updateflag);
}
echo $insertMessage;
html:
<div id="ohmygod"></div>
include another php into html file:
<input value='.$row['id'].' type=checkbox name=flag id=flag '.$tick.'>
I have one checkbox which consist of two values, 0(unchecked) and 1(checked). From above code I don't see any changes except for the background-color of the row once the user has checked the checkbox button. But it didnt update the database. My question is, what is the correct syntax to update the data instantly from checkbox selection.