Here's my html:
<tr>
<td class="tg-031e"><input type="checkbox" name="sel_a" class="a_qual" data-id23="<?php echo $row["id"]; ?>"
<?php if($row["a_qual"] == 1) { echo "checked='1'"; } ?>
></td>
<td class="a" colspan="2" data-id3="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["a"] ?></td>
</tr>
Here's my jQuery:
$(document).on('change', '.a_qual', function(){
var id = $(this).data("id23");
var a_qual = $("input[type='checkbox']").val();
edit_data(id, a_qual, "a_qual");
console.log('my message' + a_qual);
});
Here's my edit_data function:
function edit_data(id, text, column_name)
{
$.ajax({
url:"edit.php",
method:"POST",
data:{id:id, text:text, column_name:column_name},
dataType:"text",
success:function(data){
fetch_data();
}
});
}
And here's my edit.php:
include_once("includes/connection.php");
$sql = "UPDATE questions SET ".$_POST['column_name']."='".$_POST['text']."'
WHERE id='".$_POST['id']."'";
// echo $sql;
if(mysqli_query($connection, $sql))
{
echo 'Data Inserted';
}
I don't know what I'm doing well enough to make this work and I'm really stumped after reading dozens of posts across the internet. For some reason, I can get it to change my database value to "1" and then it gets stuck there. In my database I have a column named "a_qual" to store the "quality" of the checkbox and it's set to a TINYINT. Can anyone figure out my problem?
Aucun commentaire:
Enregistrer un commentaire