I'm wanting to make my code so that when I click in the checkbox to enable it, it updates a row in my database to the value 1. My checkbox is inside of my table in php and is coded around AJAX. My issue is that when I click the checkbox, 1) it doesn't do anything, (not even refresh the page using my ajax success status) : `
success: function(data) {
window.location.replace("admin_members.php");
}
2) It doesn't update my database information giving my column named 'enabled' a value of 1 for when it's checked from the PHP receiver.
My Code is Below :
Html / PHP Table (checkbox is included in here)
<td style="border: 1px solid #eee; text-align: center; font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'enabled','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["enabled"] == 1 ? '<input id="enabled-checkbox" value="1" type="checkbox" checked >' : '<input id="enabled-checkbox" value="1" type="checkbox" >'; ?></td>
AJAX Sender
function showEdit(editableObj) {
$(editableObj).css("background","#FFF");
}
function saveToDatabase(editableObj,column,id) {
$(editableObj).css("background","#FFF url('images/spin.gif') no-repeat right");
$.ajax({
url: "includes/saveedit_members.php",
type: "POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data){
window.location.replace("admin_members.php");
}
});
}
PHP Receiver
if(!isset($_POST['column']) || !isset($_POST["editval"]) || !isset($_POST["id"])) {
header('Location: error-pages/index.php');
} else if(isset($_POST['column']) && isset($_POST["editval"]) && isset($_POST["id"])) {
mysqli_query($con, "UPDATE users set " . $_POST["column"] . " = '".$_POST["editval"]."' WHERE id=".$_POST["id"]);
}
A few picture examples to help understand my database and why I'm trying to do :