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
  • 185
  • 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
  • 13,277
  • 9
  • 44
  • 71
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
  • 29,723
  • 13
  • 94
  • 101
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)
Vikram Jain
  • 5,498
  • 1
  • 19
  • 31
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
  • 8,401
  • 4
  • 40
  • 42