0

I have a sql written in python like .

cur.execute("INSERT INTO products_details(
title,
description,
price,
currency,
sku,
brand,
colors,
sizes,
actual_url,
meta_title,
meta_keywords,
meta_description,
sizefitcontainer,
designercontainer,
wearwith,
colorthumb,
colorbig,
colormedium,
discount_price,
cat_name) 
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')  ",  (
context['product_title'],
context['product_description'],
context['price'],
context['currency'],
context['productCode'],
context['brand_name'],
context['colors'],
context['sizes'],
context['actual_url'],
context['title'],
context['meta_keywords'],
context['meta_description'],
context['sizefitcontainer'],
context['designercontainer'],
context['wearwith'],
context['colorthumb'],
context['colorbig'],
context['colormedium'],
context['discount_price'],
context['cat_name']))

In above query there are two fields designercontainer , and sizefitcontainer In which I am passing some html data to store in db. But everytime I am getting some error .

(<class '_mysql_exceptions.ProgrammingError'>, ProgrammingError(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 'Cosmic Leggings'',''These cropped KORAL ACTIVEWEAR leggings have iridescent cont' at line 1"), <traceback object at 0x2bc2638>).

I tried utf encoding also which is also not able to solve this issue .Please tell me how to write the query so that both fields can accept html value (embed with js and css).

context  is a python dict.
user1481793
  • 543
  • 2
  • 13
  • 21

2 Answers2

1

You should include the structure of the product_details in your question.

Judging by the error, you have not properly quoted the HTML string that you want to store.

0

You would need to pass the data as second argument as .execute().

So it would be like

sql = '''insert into headline (column,column1) 
                   values ("%s","%s","%s","%s","%s");'''

cursor.execute(sql, (values,values1))

Here you havnt properly quoted the html string that you want to store into the database..

You can escape the values with conn.escape_string()

Have a look here

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26