By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

problem with mysql 'insert'; not working.

P: 145
I'm having trouble getting my python scripts to insert into a mysql database. I'm able to do other commands successfully such as adding or dropping tables, selecting items from tables but inserting into tables isn't working. I can manually insert but the script won't do it.
I have an entry field for a last name and am using .get() to grab the data. If I enter the name 'Jones' into the field and submit it, I get this error:
OperationalError: (1054, "Unknown column 'Jones' in 'field list'")

If I move the quotes around I won't get an error message but it also won't show up in the database.

Expand|Select|Wrap|Line Numbers
  1. mysql>INSERT INTO persons (lname) VALUES ("Jones");
  2. Query OK, 1 row affected (0.36 sec)
Script portion:
Expand|Select|Wrap|Line Numbers
  1. test4=win4a.get()     # Last name
  3. cursor.execute("INSERT INTO persons (lname) VALUE (%s)"% (test4))
If tried this which gets no errors but also doesn't insert:
Expand|Select|Wrap|Line Numbers
  1. cursor.execute("INSERT INTO persons (lname) VALUE ('%s')"% (test4))
Even if I change it to the following, I will still get the same error message:
Expand|Select|Wrap|Line Numbers
  1. cursor.execute("INSERT INTO persons (lname) VALUE ('Jones')")
Dec 20 '10 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 624
You usually have to commit for the changes to take place. See "My data disappeared!" here
Dec 21 '10 #2

P: 145
dwblas, thank you for that. It worked on my linux without the need for commit but I couldn't figure out why it wouldn't work on windows. That does the trick.
Dec 21 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.