naeg
naeg

Reputation: 4002

how to insert HTML code into a table

How can I insert a piece of HTML Code (containing " and ') into my MySQL database?

It's not that easy for me to simply escape all the " and ' with a backslash, so I'm looking for other solutions. All the solutions I have found are depended on some programming language, such as PHP, like in this example.

The programming language I'm using is Python, but I'd prefer a general mysql solution.

The piece of code I want to insert could e.g. look like this:

<tr>
<td width="140"><img alt="2345234523" src="images/stories/2345234523.png" height="105" width="140" /></td>
<td width="163">"mp3's"</td>
<td width="180">"ogg's"</td>
</tr>

(this is just random code, not neccessarly senseful or working)

Thanks in advance!

Upvotes: 0

Views: 1207

Answers (1)

Pekka
Pekka

Reputation: 449415

Generally speaking:

You need to escape data before it is inserted into the mySQL query. The Python library that provides access to mySQL should provide an escaping function to do this, or escape the data automatically using prepared statements.

The reason why string data needs to be escaped is that quotes (" or ') can break the SQL statement that is used to enter the data.

Upvotes: 2

Related Questions