473,472 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with mysql 'insert'; not working.

Thekid
145 New Member
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.

Manually:
Expand|Select|Wrap|Line Numbers
  1. mysql>INSERT INTO persons (lname) VALUES ("Jones");
  2. Query OK, 1 row affected (0.36 sec)
  3.  
Script portion:
Expand|Select|Wrap|Line Numbers
  1. test4=win4a.get()     # Last name
  2.  
  3. cursor.execute("INSERT INTO persons (lname) VALUE (%s)"% (test4))
  4.  
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))
  2.  
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')")
  2.  
Dec 20 '10 #1
2 2342
dwblas
626 Recognized Expert Contributor
You usually have to commit for the changes to take place. See "My data disappeared!" here http://mysql-python.sourceforge.net/FAQ.html.
Dec 21 '10 #2
Thekid
145 New Member
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

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

Similar topics

10
by: johnnyboy10017 | last post by:
I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that...
2
by: Hal Halloway | last post by:
I'm trying to go from PHP4 to PHP5, all seemed OK until I tried to connect to a MYSQl DB. Then I get the error message: Fatal error: Call to undefined function mysql_pconnect() in C:\Program...
4
by: Caversham | last post by:
I am trying to insert data into the fields id and term of the table key. id is an auto-incrementing field. Each of the following forms fails:- INSERT INTO key (id, term) VALUES (0, 'dog') ...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
3
by: os2 | last post by:
hi i have an insertion problem with my rtu table datatype for date1 field is: datetime i try to insert local date to the database (mysql) source code struct tm *date;
2
by: TheRomance | last post by:
i have a problem about insert integer to link list. sorry it's too long but i try many times, many ways , it's still have an error function is fix . can't change anything about function. i...
1
by: siujean | last post by:
Hi All, I met a problem when insert over 1000 records to db2 via servlet, it show me the error message is "DB2 SQL error: SQLCODE: -911, SQLSTATE: 40001, SQLERRMC: 68 DB2ConnectionCorrelator:...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
6
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the...
2
by: rahia307 | last post by:
hi i have problem in insert query and i cannot understand this probelm. please help me. code is following below. $qery = "INSERT INTO tablename(name, email) VALUES('$name', '$email')";...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.