0

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.

1
  • Please provide the error message. Commented Mar 27, 2016 at 11:54

2 Answers 2

5

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()
Sign up to request clarification or add additional context in comments.

Comments

1

When using parameters, you should not quote your parameters. That is, your query should be;

query="INSERT INTO import(customer,package) VALUES(%s, %s)"

2 Comments

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")
@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.

Your Answer

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.