0

I want to write a program in Python to control MySQL database, but the following error occurs

pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; chec
k the manual that corresponds to your MySQL server version for the right syntax
to use near 'Code,type, number,Whether )VALUES ('cl8k-k520-fg45-d4sa-sd9k','n' at line 1")

Code:

import pymysql 
db = pymysql.connect("localhost", "root", "root", "test")
cursor = db.cursor()
sql = "INSERT INTO BOOKS(Activation Code, \
 type, number,Whether ) \
 VALUES (%s,%s,%s,%s)"
data = [("cl8k-k520-fg45-d4sa-sd9k",'n','10','n'),
 ("jhg6-58jh-gh8o-8uik-7jk8",'c','20','n'),
 ("x5hg-gf5h-4hj5-g4h5-fh5t",'y','999','n'),
 ("fg8j-h584-fd4g-fg4d-fgg4",'n','1','y'),
 ("4jk4-5kl4-4klk-4lji-4ghj",'e','6','n'),
 ]
cursor.executemany(sql,data)
db.close()

This is my first time to ask questions on this platform. I hope to get answers

asked Apr 1, 2020 at 3:29
1

1 Answer 1

1

enclose Activation Code as 'Activation Code'

answered Apr 1, 2020 at 3:41
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. I'll never make a mistake again

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.