Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: MySQLdb insert HTML code error

Reply
Thread Tools

Re: MySQLdb insert HTML code error

 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      12-11-2012
On Tue, 11 Dec 2012 01:04:44 +0100, Anatoli Hristov <(E-Mail Removed)>
declaimed the following in gmane.comp.python.general:

> Hi all,
>
> I'm facing an issue inserting an html code into the DB, it comes out
> with a syntax error but I face it only when I have html code. Could
> help me escape the error somehow ?
>
> Here is my code
>
> def InsertSpecsDB(product_id, spec, lang, name):
> db = MySQLdb.connect("localhost","getit","opencart")
> cursor = db.cursor()
> sql = ("INSERT INTO product_description (product_id, language_id,
> name, description) VALUES ('%s','%s','%s','%s')")


First thing -- DON'T put quotes around the %s place-holders... The
whole purpose of using the parameterized .execute() is to let the
database adapter properly escape the parameters before putting them into
the SQL (since MySQL didn't have prepared statements before v5, it was
producing full SQL statements for each insert, even with .executemany()
)
--
Wulfraed Dennis Lee Bieber AF6VN
http://www.velocityreviews.com/forums/(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: MySQLdb insert HTML code error Mark Lawrence Python 0 12-11-2012 12:38 AM
Re: MySQLdb insert HTML code error Anatoli Hristov Python 0 12-11-2012 12:31 AM
Re: MySQLdb insert HTML code error Anatoli Hristov Python 0 12-11-2012 12:29 AM
Re: MySQLdb insert HTML code error Mark Lawrence Python 0 12-11-2012 12:22 AM
MySQLdb insert HTML code error Anatoli Hristov Python 0 12-11-2012 12:04 AM



Advertisments