My alerted values from SUCCESS function are correct. They are:
serviceID=123&acceptAgreement=on
acceptAgreement is a input checkbox.
DB file is not being updated. I tried var_dump($_POST) from ajax URL file and nothing happens. I think it's not 'finding' the URL which resides in a subdirectory of main directory. My js file:
$("#frmServiceAgreement").submit(function(event){
var values = $(this).serialize();
if($("input[name^='acceptAgreement']").is(":checked")) {
$.ajax({
url: "/admin/service.php",
type: "post",
data: values,
success: function(result){
window.alert(values);
},
error:function(){
alert("failed");
console.log("ooops!");
}
});//end ajax
} else {
$(".popup").fadeIn('slow');
}
event.preventDefault();
});
My URL file is service.php in a subdirectory admin/service.php (NOTE:maybe my if statement needs to be changed as my alerted value of acceptAgreement is ON not 1 which is the value that I want to store in my tinyint column in db.
<?php
include('../xxx/functions.php');
$serviceID = protect($db,$_POST['serviceID']);
$acceptAgreement = protect($db,$_POST['acceptAgreement']);
if($acceptAgreement==1){
$sql = $db->query("UPDATE services SET serviceAgreement=1 WHERE id=$serviceID");
} else {
$sql = $db->query("UPDATE services SET serviceAgreement=0 WHERE id=$serviceID");
}
?>