I am using ckeditor to create a blog site. I want to use a combination 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?
Yes, 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With