I have error while trying to insert data to database. Searched google for answer but didn't found any answer.
def zapisi_racune():
global curug_strvar, novisad_strvar, gospodjinci_strvar, djurdjevo_strvar, datum_strvar
curug = curug_strvar.get()
novisad = novisad_strvar.get()
gospodjinci = gospodjinci_strvar.get()
djurdjevo = djurdjevo_strvar.get()
datum = datum_strvar.get()
if not curug or not novisad or not gospodjinci or not djurdjevo:
mb.showerror('Informacije o spakovanim računima', "Morate popuniti sva polja za ova naselja!")
else:
try:
connector.execute(
'INSERT INTO SPAKOVANI_RACUNI (CURUG, NOVISAD, GOSPODJINCI, DJURDJEVO) VALUES (?,?,?,)', (curug, novisad, gospodjinci, djurdjevo, datum)
)
connector.commit()
mb.showinfo('Informacije o spakovanim računima', f"Evidencija uspešno dodata!")
#reset_fields()
prikazi_racune()
except:
mb.showerror('Informacije o spakovanim računima', 'Polja moraju sadržati brojeve!')`
CodePudding user response:
On the following line
connector.execute(
'INSERT INTO SPAKOVANI_RACUNI (CURUG, NOVISAD, GOSPODJINCI, DJURDJEVO) VALUES (?,?,?,)',
(curug, novisad, gospodjinci, djurdjevo, datum)
)
you are using three placeholders and passing five variables. Moreover, you are specifying four columns (CURUG, NOVISAD, GOSPODJINCI, DJURDJEVO
) inside the query.
You are supposed to specify N columns and N placeholders with N corresponding variables in order for to query to succeed.