Tomas Turan
Tomas Turan

Reputation: 1255

How to store formatted text with HTML tags to database and then display it?

I'm using Laravel framwork and I have a WYSIWYG editor in my form.

Input::get('wysivyg') 

Is returning HTML output, for example:

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

So I'm getting this error:

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, , , ))

This is the line that is returning error:

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')));

How could I store formatted text to database?

Upvotes: 0

Views: 1319

Answers (1)

Quentin
Quentin

Reputation: 943605

The error has nothing to do with the HTML.

text, range and date are reserved words in SQL. You can't use them as column names in a query unless you surround them with backticks.

Upvotes: 1

Related Questions