2014-12-02 35 views
0

我使用的是Laravel框架,我的表單中有一個所見即所得的編輯器。如何將帶HTML標籤的格式化文本存儲到數據庫中,然後顯示它?

Input::get('wysivyg') 

將返回HTML輸出,例如:

<p><strong>dsdsdd</strong></p> <p><em>dsdsd</em></p> <p>&nbsp;</p> 

所以我得到這個錯誤:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'range, investor, designer, contractor, area, date) VALUES (?, ?, ?, ?, ?, ?, ?, ' at line 1 (SQL: INSERT INTO projects (name, city, category, text, range, investor, designer, contractor, area, date) VALUES (sssa, sasas, garden, <p><strong>dsdsdd</strong></p> <p><em>dsdsd</em></p> <p>&nbsp;</p> , , , sasaasas, , ,)) 

這是返回錯誤的行:

DB::insert('INSERT INTO projects (name, city, category, text, range, investor, designer, contractor, area, date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', 
    array(Input::get('name'), Input::get('city'), Input::get('category'), Input::get('wysiwyg'), Input::get('range'), Input::get('investor'), Input::get('designer'), 
      Input::get('contractor'), Input::get('area'), Input::get('date'))); 

如何存儲格式化文本t數據庫?

回答

1

該錯誤與HTML無關。

text,rangedate是SQL中的reserved words。除非用反引號包圍它們,否則不能將它們用作查詢中的列名稱。

相關問題