I am using ckeditor to create a blog site. I want to use a bination of PHP and MySQL to save the entire article in a database. If I submit the form holding the ckeditor I get the editor's content in $_POST['editor']
. I want to save the article in the MySQL database. The following image contains the entire form data. It consists of:
title inside title element.
article(text,code-snippet,image) inside "editor1" element.
$_POST['editor']
array looks like:
How can I save it to a mysql table? Can I save the entire editor1 element in a column of type TEXT?
I am using ckeditor to create a blog site. I want to use a bination of PHP and MySQL to save the entire article in a database. If I submit the form holding the ckeditor I get the editor's content in $_POST['editor']
. I want to save the article in the MySQL database. The following image contains the entire form data. It consists of:
title inside title element.
article(text,code-snippet,image) inside "editor1" element.
$_POST['editor']
array looks like:
How can I save it to a mysql table? Can I save the entire editor1 element in a column of type TEXT?
Share Improve this question edited Feb 2, 2017 at 15:05 Sᴀᴍ Onᴇᴌᴀ 8,2978 gold badges37 silver badges60 bronze badges asked Dec 24, 2015 at 20:53 AL-zamiAL-zami 9,06617 gold badges76 silver badges135 bronze badges3 Answers
Reset to default 12Yes, You can submit your entire article to the database. But, before you submit it; try to use this function:
function dataready($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
Example:
dataready($_POST['editor']);
So you can use whatever you want PDO or Mysqli.
To avoid echoing the HTML elements when you print the article, use this function:
html_entity_decode($article_text);
Hope this works for you.
PS. using column type TEXT for your database is fine. You can also use LONGTEXT if you want to add more text to that column.
Yes, you can store the Source Code in your database, that's how Wordpress works.
But remember to escape the strings before sending them to database, using:
mysqli_escape_string();
When you get the post data afterwards, the PHP will just print the HTML on the screen.
Simple and easy use base64_encode()
$content = base64_encode($editor_content);
and when you fetch data use base64_decode()
$content = base64_decode($editor_content);