1

I'm trying to use mysql 5.1 with python 2.6.6 and I'm getting the following error. code :

   query = "INSERT INTO present_list SET from='a', to='b'" 
   print query
   cur.execute(query)

error :

   Error 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 'from='a', to='b'' at line 1

Can somebody understand what is wrong ?

4 Answers 4

2

You need to use the backstroke in from and to like :

INSERT INTO present_list SET `from`='a', `to`='b

Since from is a keyword in mysql

Sign up to request clarification or add additional context in comments.

Comments

2

Put a back strike before from. From is one of MySQL's reserved words

query = "INSERT INTO present_list (`from`, `to`) VALUES ('a', 'b')" 
print query
cur.execute(query)

Comments

1
Please, learn SQL and Syntex then work on :
Your answer is:

For Insert Data into table
============================    
query = "INSERT INTO present_list(from,to) values('a'.'b')"; 
       print query
       cur.execute(query)

For Update Data into table
============================

query = "Update present_list set from='a', to='b'"; 
       print query
       cur.execute(query)

Comments

0

from and to are mysql reserved words. So if you want to use them as normal names please use backtick(`) symbol around reserved word. For more info please goto Select a column with a keyword name

Comments

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.