1

I am trying to Inserat something from Input into my Database. But getting the Error:

sqlite3.OperationalError: no such column: kundename

import sqlite3

conn = sqlite3.connect('datenbank.db')
print ("Opened database successfully")

kundenname= input("Kundename: ")
auftragstyp= input("Auftragstyp: ")
auftragsurl= input("Auftragsurl: ")
anzahl= input("Anzahl der Bewertungen: ")

conn.execute("INSERT INTO kundenname VALUES (kundename,auftragstyp,auftragsurl,anzahl)", (kundenname, auftragstyp,         auftragsurl,  anzahl))

conn.commit()
print ("Records created successfully")
conn.close()

But if I make like:

import sqlite3

conn = sqlite3.connect('datenbank.db')

print ("Opened database successfully")

conn = conn.execute("SELECT ID, kundename from kundenname")
for row in conn:
print ("ID = ", row[0])
print ("kundename = ", row[1])
print ("Operation done successfully")
conn.close()

then it works and Shows me the Datas in the Base. But why insert saying the colum dosent excist?

Thank you very much!

2
  • Typo in kundenname? Commented Jan 31, 2018 at 12:26
  • No, I wrote it like this in DB to ;) Commented Jan 31, 2018 at 12:37

2 Answers 2

1

I think you have a problem with this line:

conn.execute("INSERT INTO kundenname VALUES 
(kundename,auftragstyp,auftragsurl,anzahl)", (kundenname, auftragstyp,         
auftragsurl,  anzahl))

This is not the way to insert, try this:

conn.execute("INSERT INTO kundenname 
('kundename','auftragstyp','auftragsurl','anzahl') VALUES (" + 
str(kundename) +"," + str(auftragstyp) + "," +  str(auftragsurl) + "," 
+ str(anzahl)+")"
Sign up to request clarification or add additional context in comments.

5 Comments

It says then: sqlite3.OperationalError: no such column: Michi , he looking as colum what I put into the Input.
Only works if I use numbers as Input.. if I add letters then it Comes the error that the colum dosent excist emm
That's because SQL requires single quotes around each string value, but not for numeric values. So it all depends on your database field types as to how you insert the data. So if auftragsurl is a text field, the VALUE should be like ...",'" + str(auftragsurl) + '","... and an integer insertion looks like ..., anzahl,... assuming anzahl is an integer.
I have as kundename ...+ str(kundename) +... and in database kundename is Text. Still he dont add it in the database, he search the Input as a colum and but adding a number it works.. but why if it is TEXT :)
I did not understand if it helped you or not...can you please post the updated code?
0

The interpreter is complaining about your using unquoted strings. It's interpreting them as variable names in your insert statement. Try this:

conn.execute("INSERT INTO kundenname ('kundename','auftragstyp','auftragsurl','anzahl') VALUES (kundenname, auftragstyp,  auftragsurl,  anzahl)")

4 Comments

Thanks! Getting the error: sqlite3.OperationalError: near ",": syntax error
The problem was the comma before the word VALUE. I removed it from the answer.
sqlite3.OperationalError: no such column: kundenname
And if I Change it into: + str(kundenname) + , it Comes: sqlite3.OperationalError: no such column: Hans

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.