2016-08-15 110 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