Exception or error:
I’m playing around with CKEditor5 but couldn’t get it to work. Here is my Code
<div name="content" id="editor" onblur="saveOnBlur(1,'alias')">
<p>Here goes the initial content of the editor.</p>
</div>
<button id="getdata">Print data</button>
<script>
let theEditor;
BalloonEditor
.create(document.querySelector('#editor'))
.then(editor => {
theEditor = editor;
})
.catch(error => {
console.error(error);
});
function getDataFromTheEditor() {
return theEditor.getData();
}
function saveOnBlur(id,column) {
var editval = getDataFromTheEditor();
$.ajax({
url: "submit.php",
type: "POST",
data: 'column='+column+'&editval='+editval+'&id='+id,
success: function(data){
alert('column='+column+'&editval='+editval+'&id='+id);
}
});
}
</script>
php File (submit.php)
$pdo_statement=$pdo->prepare("UPDATE posts set " . $_POST["column"] . " = '".$_POST["editval"]."'
WHERE id=".$_POST["id"]);
$result = $pdo_statement->execute();
Maybe i don’t see the Forest for the Trees, but after leaving the editor div, the alert fires but my PHP File doesn’t save in Database, so i think there is something wrong with mit $_POST[”] values. Maybe someone can give me a push in the right direction.
How to solve:
Okay, it was the wrong table, everything is working in this code. Thanks for reading.