Skip to Content
How to save ckeditor text in database php
php code / September 26, 2021


The HTML prepared content can be inserted into the input area using the WYSIWYG editor. Using the jQuery plugin, you can simply add a WYSIWYG HTML editor to a textarea. To add a WYSIWYG editor to texarea, there are several jQuery plugins available. The most common plugins for adding a rich text editor to a web page are CKEditor and TinyMCE.

The value must be saved for further usage after the WYSIWYG editor text is submitted. The database is typically used to store the input content in a web application. The input HTML value must be placed into the database to save the WYSIWYG editor content. The PHP $_POST function is the most convenient approach to retrieve HTML editor values and save WYSIWYG Editor content to the database. In this article, we’ll teach you how to use PHP and MySQL to insert and save HTML content from a WYSIWYG editor into a database.

Make a database table.

A table in the database must be created to store the HTML editor content. In the MySQL database, the following SQL creates an editor table with some basic fields.

CREATE TABLE `editor` (
`content` text COLLATE utf8_unicode_ci NOT NULL,
`created` datetime NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Configuring the Database (dbConfig.php)

The dbConfig.php file is used to connect PHP and MySQL to the database. According to your database credentials, specify the database host ($dbHost), username ($dbUsername), password ($dbPassword), and name ($dbName).

// Database configuration
$dbHost = "localhost";
$dbUsername = "root";
$dbPassword = "root";
$dbName = "codexworld";
// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);

Form with a WYSIWYG HTML Editor

Create an HTML form with a textarea input field to allow the user to enter information and submit it.

<form method="post" action="submit.php">
<textarea name="editor" id="editor" rows="10" cols="80">
This is my textarea to be replaced with HTML editor.
<input type="submit" name="submit" value="SUBMIT">

The textarea element must be converted in WYSIWYG Editor to accept HTML material from the user. To add an HTML editor to a textarea input field, you can use any WYSIWYG editor plugin (CKEditor or TinyMCE).
With CKEditor, you may add a WYSIWYG editor:
Include the CKEditor plugin’s JS library file.

<script src="ckeditor/ckeditor.js"></script>

To replace the textarea field with a WYSIWYG editor, use the CKEDITOR.replace() method.


Include the TinyMCE editor plugin’s JS library file to add a WYSIWYG editor.

<script src="tinymce/tinymce.min.js"></script>

To replace the textarea field with a WYSIWYG editor, use the tinymce.init() method.

selector: '#editor'

Content from the HTML Editor should be saved in the database.

The editor’s input is posted to the server-side script (submit.php) for inserting the HTML formatted content in the database once the form is submitted.

Using PHP’s $_POST function, get the editor content from the sent form data.
Using PHP and MySQL, insert the HTML content into the database.
The user will see the status message.

// Include the database configuration file
require_once 'dbConfig.php';
$editorContent = $statusMsg = '';
// If the form is submitted
// Get editor content
$editorContent = $_POST['editor'];
// Check whether the editor content is empty
// Insert editor content in the database
$insert = $db->query("INSERT INTO editor (content, created) VALUES ('".$editorContent."', NOW())");
// If database insertion is successful
$statusMsg = "The editor content has been inserted successfully.";
$statusMsg = "Some problem occurred, please try again.";
$statusMsg = 'Please add content in the editor.';

Note :

You can use the example code to enter any HTML editor content in the database, not just the CKEditor and TinyMCE editor material. This code snippet comes in handy when using the WYSIWYG editor to input HTML text in a CRUD application. You may easily extend the functionality of our script by utilising a WYSIWYG editor to add extra input fields and save all of the material to the database using PHP and MySQL.



fer says:

Thanks for helping those of us who are learning but I have a problem that doesn’t work in production and it’s that the styles are not inserted in the database with the html and I don’t know what I can do for this problem if you can help me thank you very much hello this is the problem

Woah! I’m really digging the template/theme of this blog. It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between user friendliness and appearance. I must say you’ve done a great job with this. Also, the blog loads very quick for me on Chrome. Outstanding Blog!

You can certainly see your expertise within the work you write. The world hopes for even more passionate writers like you who are not afraid to say how they believe. Always follow your heart.


We have hacked y0ur website and extracted y0ur databases.

How did this happen?

0ur team has f0und a vulnerability within y0ur site that we were able to exploit. After finding the vulnerability we were able t0 get your database credentials and extract your entire database and m0ve the informati0n to an offshore server.

What does this mean?

We will systematically g0 thr0ugh a series of steps 0f t0tally damaging y0ur reputation. First your database will be leaked or sold to the highest bidder which they will use with whatever their intenti0ns are. Next if there are e-mails f0und they will be e-mailed that their inf0rmati0n has been s0ld 0r leaked and your site was at fault thusly damaging your reputati0n and having angry customers/associates with whatever angry customers/associates d0. Lastly any links that y0u have indexed in the search engines will be de-indexed based 0ff of blackhat techniques that we used in the past t0 de-index our targets.

How d0 i stop this?

We are willing t0 refrain from destr0ying y0ur site’s reputation for a small fee. The current fee is $3000 in bitcoins (.16 BTC).

Please send the bitcoin to the f0llowing Bitcoin address (Make sure t0 copy and paste):


0nce you have paid we will automatically get informed that it was y0ur payment. Please note that you have to make payment within 5 days after receiving this e-mail 0r the database leak, e-mails dispatched, and de-index of your site WiLL start!

H0w do i get Bitcoins?

Y0u can easily buy bitcoins via several websites 0r even 0ffline fr0m a Bitcoin-ATM.

What if i d0n’t pay?

if you decide not t0 pay, we will start the attack at the indicated date and uph0ld it until you do, there’s n0 c0unter measure t0 this, you will 0nly end up wasting m0re money trying to find a solution. We will completely destroy your reputati0n amongst go0gle and your cust0mers.

This is not a hoax, do n0t reply to this email, don’t try to reason or neg0tiate, we will n0t read any replies. 0nce you have paid we will stop what we were d0ing and y0u will never hear from us again!

Please n0te that Bitcoin is anonymous and n0 0ne will find out that you have c0mplied.

Wonderful post however I was wanting to know if you could write a litte more on this subject? I’d be very grateful if you could elaborate a little bit more. Appreciate it!

You can definitely see your enthusiasm within the work you write. The sector hopes for more passionate writers such as you who aren’t afraid to say how they believe. Always go after your heart. “Faith in the ability of a leader is of slight service unless it be united with faith in his justice.” by George Goethals.

Nice post. I was checking constantly this blog and I am impressed! Extremely useful info specifically the last part 🙂 I care for such info a lot. I was looking for this certain info for a long time. Thank you and best of luck.

Hi, i feel that i saw you visited my weblog thus i got here to “go back the favor”.I am attempting to to find issues to improve my web site!I assume its ok to make use of some of your ideas!!

Great wordpress blog here.. It’s hard to find quality writing like yours these days. I really appreciate people like you! take care

I intended to send you the very small note in order to thank you again about the exceptional opinions you’ve shared on this site. It has been certainly particularly open-handed of you to present easily exactly what some people would have offered as an ebook to generate some cash on their own, chiefly considering that you could possibly have done it if you decided. Those guidelines also served like a easy way to be sure that someone else have the identical keenness just as my personal own to know a whole lot more in regard to this matter. I am sure there are numerous more pleasurable opportunities in the future for people who look into your blog.

Hello my loved one! I wish to say that this article is amazing, nice written and come with approximately all important infos. I?¦d like to see extra posts like this .

Leave a Reply

Your email address will not be published.

PHPCODE © 2023