MANI VANNAN
MANI VANNAN

Reputation: 1

cant insert data into mysql using python

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.

Upvotes: 0

Views: 1082

Answers (2)

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

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

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

Upvotes: 1

Yash Mehrotra
Yash Mehrotra

Reputation: 3120

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()

Upvotes: 5

Related Questions