I am using TinyMCE textarea. Which will be formatted text
How I can insert that formatted text into table (database) as well as print value that I have inserted (formatted text) ?

mysql_query("insert into emailtemplates (name, messagebody, status) values('".$_POST['frmname']."', '".$_POST['content']."', $status)")

where $_POST is my textarea

Recommended Answers

All 2 Replies

I will try to explain my approach since I also use TinyMCE. I use two divs: the first div holds a textarea (TinyMCE editor), a Save button and a Cancel button. The other div holds edited text as an ordinary paragraph and an Edit button. One div is hidden (display:none) and the other shown (display:block). By clicking on Edit button, the paragraph and Edit button div gets hidden and the textarea (editor) and buttons div gets displayed. By clicking Save or Cancel the editor and buttons div gets hidden, the content saved through ajax and paragraph div gets displayed with updated contents.

All this can be accomplished with Javascript functions. To manage the contents of an editor you have to get the instance of TinyMCE:

var ed = tinyMCE.get(edName)

To get the edited text from the editor use

var contents = ed.getContent();

You send the contents to a saving php script with ajax (this target php script contains code to save to DB). You update the paragraph that displays the contents with the text from the editor.

document.getElementById(contentsDivId).innerHTML = contents;

This is just an explanation of my approach and will hopefully help you in solving your problem.


you'll need to format the text before you input it into your db, which can be done in a few different ways:

if(isset($_POST['textarea'])) {
 $textarea = mysql_real_escape_string($_POST['textarea']);


if(isset($_POST['textarea'])) {
 $textarea = addslashes($_POST['textarea']);

Depending on how secure you need to be. Complete the MySQL INSERT the way you normally would. Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.