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 ?

billx
  • 175
  • 11

4 Answers4

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

Sashi Kant
  • 12,829
  • 9
  • 40
  • 65
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)
ajtrichards
  • 28,323
  • 13
  • 90
  • 97
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)
jainvikram444
  • 5,282
  • 1
  • 17
  • 30
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

Community
  • 1
  • 1
Fathah Rehman P
  • 7,971
  • 4
  • 38
  • 42