I want to pass js function arguments "checklistNoteId" and "checklistNoteStatus" to PHP variable, so I can change things in database. What code should I write to pass those arguments? I have tried to do it but it doesn't work. An example of my problem is bellow:
EDIT: I've tried this, but it didn't help me.
JS CODE:
checklistFinishedBtn.onclick = function(e){
let noteId = Number(e.target.parentNode.getAttribute('checklist-id'));
if (checklistArray.checklistItems[noteId].isDone){
changeChecklistNoteStatus(checklistArray.checklistItems[noteId].id, 0);
} else {
changeChecklistNoteStatus(checklistArray.checklistItems[noteId].id, 1);
}
}
PHP CODE:
<head>
<script>
function changeChecklistNoteStatus(checklistNoteId, checklistNoteStatus){
console.log(checklistNoteId); //this returns 26 (which is correct)
console.log(checklistNoteStatus); //this returns 1 (which is correct)
<?php
//if I set these values manually, it works
$status = "<script>document.write(checklistNoteStatus)</script>";
$id = "<script>document.write(checklistNoteId)</script>";
$sql = 'UPDATE checklist_notes SET isDone = :isDone WHERE id = :id';
$statement = $pdo->prepare($sql);
$statement->execute(['isDone' => $status,'id' => $id]);
?>
}
</script>
</head>
After this, the database remains untouched. (I am trying to set the note with id 26 to change isDone variable on button click.)
The screen from database is here: