Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
pet cannot be added 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 'of birth, gender_id, cat_id, picture, instock) values ('coco','pitbull','425....' at line 1


sql = "INSERT into tblpet (name, breed, price, color, age, date of birth, gender_id, cat_id, picture, instock) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
#add the form variables for each column
val = (name, breed, price, color,age,dt, gender, cat, filepath, instk)
cur.execute(sql, val)
con.commit()

What I have tried:

i checked all my database and checked the code but enable to find the problem.
Posted

1 solution

You have a column called date of birth, which always needs to be escaped using backticks:
MySQL :: MySQL 8.0 Reference Manual :: 11.2 Schema Object Names[^]
SQL
INSERT into tblpet (name, breed, price, color, age, `date of birth`, gender_id, cat_id, picture, instock) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
A better option would be to rename your column so that it doesn't contain spaces - for example, date_of_birth.
 
Share this answer
 
Comments
Maciej Los 13-Feb-24 16:23pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900