problem with mysql 'insert'; not working.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thekid
    New Member
    • Feb 2007
    • 145

    problem with mysql 'insert'; not working.

    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:
    OperationalErro r: (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.

    Manually:
    Code:
    mysql>INSERT INTO persons (lname) VALUES ("Jones");
    Query OK, 1 row affected (0.36 sec)
    Script portion:
    Code:
    test4=win4a.get()     # Last name
    
    cursor.execute("INSERT INTO persons (lname) VALUE (%s)"% (test4))
    If tried this which gets no errors but also doesn't insert:
    Code:
    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:
    Code:
    cursor.execute("INSERT INTO persons (lname) VALUE ('Jones')")
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    You usually have to commit for the changes to take place. See "My data disappeared!" here http://mysql-python.sourceforge.net/FAQ.html.

    Comment

    • Thekid
      New Member
      • Feb 2007
      • 145

      #3
      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.

      Comment

      Working...