2016-08-15 105 views
-1

我使用tinymce作为我从中提交消息的表单,它不会将其插入到数据库中 我检查了SQL,它只是试图将代码插入到数据库中。这有点像从富文本编辑器插入代码到数据库中

INSERT INTO news (news_title, news, time_added) VALUES (some title, `<p>some text <strong>some strong text</strong></p>`, NOW()) 

,它只是没有把它插入到数据库中 有人可以解释我为什么,我必须做什么?

+0

使用预处理语句。还提供您正在尝试执行的代码。 – Tschallacka

回答

1

需要HTML编码的内容,然后插入

使用像htmlentities($str)

例子:

encodedStr = htmlentities($html); 

为了解码:

$html = html_entity_decode($encodedStr); 
+0

现在它插入它,但它打印原始html –

+1

是的,所以当你打印时,你需要将原始html转换回非转义形式a = htmlentities($ orig); $ b = html_entity_decode($ a); – varun