Can't insert more than two data's in the mysql database i'm running the code in python using raspberry pi. the code i used is
query="INSERT INTO import(customer,package) VALUES('%s','%s')"
cursor.execute(query,(name,data))
it gives an error to check the syntax.
-
Please provide the error message.Gustavo Straube– Gustavo Straube2016年03月27日 11:54:16 +00:00Commented Mar 27, 2016 at 11:54
2 Answers 2
You also need to add connection.commit() after your insert/update queries.
Example
connection = MySQLdb.connect(*data)
cursor = connection.cursor()
cursor.execute(<query>)
connection.commit()
answered Mar 27, 2016 at 9:40
Yash Mehrotra
3,1601 gold badge23 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
When using parameters, you should not quote your parameters. That is, your query should be;
query="INSERT INTO import(customer,package) VALUES(%s, %s)"
answered Mar 27, 2016 at 9:40
Joachim Isaksson
182k28 gold badges298 silver badges308 bronze badges
2 Comments
MANI VANNAN
Traceback (most recent call last): File "/home/pi/newread.py", line 40, in <module> cursor.execute(query,(name,data)) File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute self.errorhandler(self, exc, value) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue 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 '),'006078648')' at line 1")
Joachim Isaksson
@MANIVANNAN Is the code in the query the exact code you're getting this error with? Looks like the query you're getting the error on isn't parameterized a'la what you're showing.
default