user2666864
user2666864

Reputation: 67

saving formatted text in mysql database

I have a textarea and I am using WYSIWYG editor so that the users can format the text as they want: changing colors, making bold, changing size etc.. The problem is after I insert the data to the table and retrieve the rows, I don't see the formatting, just plain text. Is there something that I should do when inserting the text not to loose the format? my table collation is set to utf8_unicode_ci

Here is the html and I am using ajax to send the form so I don't have name attribute

<textarea  id="description" class="jqte-test" ></textarea>

The insert query is as below:

$desc = trim(strip_tags($_POST["description"]));
$insert = $mysqli->prepare("insert into `test`(`description`) values(?)");
echo $mysqli->error;
$insert->bind_param('s', $desc);
$insert->execute();

Upvotes: 3

Views: 11787

Answers (1)

sUP
sUP

Reputation: 624

strip_tags is used to strip html/php tags from a value.

I would guess that the WYSIWYG editor you use outputs html data, so by using the strip_tags function you are canceling the formatting.


UPDATE: when you bind a parameter to a query through pdo it escapes the inserted data.

when inserting the data apply htmlspecialchars($value, ENT_QUOTES)

and when displaying the data apply htmlspecialchars_decode($value, ENT_QUOTES)

Upvotes: 5

Related Questions