Reputation: 27
Can Anyone Help Me to Fix This Problem This is my code why it can't detect the column? sqlite3.OperationalError: no such column: None
import sqlite3
import tkinter
from tkinter import *
from tkinter import ttk
def Daftar():
window = Tk()
window.title("Welcome to TutorialsPoint")
window.geometry('400x400')
window.configure(background = "grey");
Lnpm = Label(window, text="Please Input Your npm: ").grid(row=0, column=0)
Lnama = Label(window,text="Please Input Your nama: ").grid(row=1, column=0)
Ljurusan = Label(window,text="Please Input Your jurusan: ").grid(row=2, column=0)
npm1 = Entry(window).grid(row = 0,column = 1)
nama1 = Entry(window).grid(row = 1,column = 1)
jurusan1 = Entry(window).grid(row = 2,column = 1)
def Clicked():
npm = npm1
nama = nama1
jurusan = jurusan1
connect = sqlite3.connect('C:///Users///Marvin///Desktop///FaceRecognition-Presernsi-sql///SQL///Presensi.db')
cur = connect.cursor()
connect.execute("INSERT OR IGNORE INTO user(npm,nama,jurusan) Values("+str(npm)+",' "+str(nama)+" ',' "+str(jurusan)+" ' )")
connect.execute("INSERT OR IGNORE INTO presensi(nama) Values(' "+str(nama)+" ')")
connect.commit()
cur.close()
tn = ttk.Button(window ,text="Register",command=Clicked).grid(row=3,column=0)
Upvotes: 0
Views: 1415
Reputation: 6474
Check the following columns actually exist in the table user
: npm, nama, jurusan
; and in table presensi
: nama
.
connect.execute("INSERT OR IGNORE INTO user(npm,nama,jurusan) Values("+str(npm)+",' "+str(nama)+" ',' "+str(jurusan)+" ' )") connect.execute("INSERT OR IGNORE INTO presensi(nama) Values(' "+str(nama)+" ')")
If you are trying to update text columns like this you have to surround the values with quotes, i.e. it should be ...values('" + str(npm) + "'"...
However, building the sql query like this leads to the possibility of sql injection attacks. It's better to use parameterised queries instead, using placeholders:
cur.execute("INSERT OR IGNORE INTO user(npm,nama,jurusan) values(?,?,?)", (str(npm),str(nama),str(jurusan))
cur.execute("INSERT OR IGNORE INTO presensi(nama) values(?)", (str(nama),))
Upvotes: 1