Reputation: 47
I am trying to insert html to mysql table using Python script. That way i want to edit article on my website, so the html has to be valid. This is an error i receive:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to use
near 'n1'>Poniedziałek 30.08.2021r.</p>
<p>
<b>6<sup>30</sup></b> za zmarłych ro...' at line 1
Perhaps there is a problem with special characters like /n
, /t
or '
. Unfortunately I don't know how to solve that problem.
Here is part of code that I am trying to execute:
mycursor.execute("UPDATE `table_name` SET `col_name` = '" + doc_html + "' WHERE `table_name`.`id` = 1")
Beginning of doc_html
(which is a string variable):
<html>\n<style>\n p {\n margin: 0em 0in;\n font-size: 1em;\n font-family: "Georgia", serif;\n color: black;\n text-align: left;\n }\n\n p.n1 {\n margin: 1.5em 0in 0.25em;\n font-size: 1.25em;\n font-family: "Georgia", serif;\n color: black;\n font-weight: bold;\n text-align: center;\n }\n\n ol.zbiorowa {\n margin: 0;\n font-family: "Georgia", serif;\n }\n\n br {\n line-height: 50%;\n }\n</style>\n\n\n\n<p class=\'n1\'>Poniedziałek 30.08.2021r.</p>\n<p>\n\t<b>6<sup>30</sup></b> za zmarłych rodziców chrzestnych: za + Janinę Sokołowską i za + Jana Cichonia<br/>\n\t<b>6<sup>30</sup></b> za
Please help!
Upvotes: 0
Views: 91
Reputation: 49375
use parameters
mycursor.execute("UPDATE `table_name` SET `col_name` = &s WHERE `table_name`.`id` = 1",(doc_html,))
Soy you can avoid to handle the characters that could cause that problem
Upvotes: 1