Reputation: 71
I'm using HTML5 text editor, using which people can
How do I store and retrieve this data in/from mysql database so that the formatting is preserved? Currently, the text is getting stored, but as plain text.
What approach should I adopt to fix this issue?
Upvotes: 1
Views: 4894
Reputation: 13303
Use htmlentities()
function and in MySQL use TEXT as field type of the attribute
let the element has id editor
then in js
use
$('#editor').html();
Example:
<div id="editor">
<!--Here goes your content from HTML5 Editor-->
</div>
so use AJAX to save it:
function StoreText() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText == "true") {
//success message
} else {
//error message
}
}
}
xmlhttp.open("POST", "Update.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("value=" + $('#editor').html());
}
Upvotes: 2