我想要一個與我制作的注冊資料庫相關的登錄系統
我正在嘗試進行一個復雜的查詢,該查詢需要用戶輸入:
Entry(self.root,
textvariable=self.username) ##There is more but I want this to be as minimal as possible
Entry(self.root,
textvariable=self.password,
show="*")
然后將該用戶輸入與資料庫中的輸入進行比較。 這是我覺得困難的地方:
def login(self):
con = sqlite3.connect("register.db") ##The database which I want to open and compare user inputs to
c = con.cursor()
c.execute("SELECT * FROM register")
slist = c.fetchall()
values = [row[0] for row in slist]
values2 = [row[1] for row in slist]
if self.username.get() == values and self.password.get()==values2:
command=self.invcon ##A external thing I want to open if the user enters the data in correctly
else:
messagebox.showerror("Error","Error"parent=self.root)
con.commit()
con.close()
現在發生的錯誤不是打開新視窗而是移動到其他視窗并彈出錯誤框。 資料庫
uj5u.com熱心網友回復:
SQL"SELECT username * FROM register"應該是"SELECT * FROM register".
和是串列,所以字串(或)values和串列之間的比較總是。values2self.username.get()self.password.get()False
但是,您不需要從表中選擇所有記錄,只需選擇具有用戶名和密碼的記錄即可:
def login(self):
con = sqlite3.connect("register.db") ##The database which I want to open and compare user inputs to
c = con.cursor()
# assume the fields required are 'username' and 'password'
# change them to suit your table definition
c.execute("SELECT 1 FROM register WHERE username = ? AND password = ?", (self.username.get(), self.password.get()))
result = c.fetchone() # get the record if any
if result:
# record found
command=self.invcon ##A external thing I want to open if the user enters the data in correctly
else:
# record not found
messagebox.showerror("Error", parent=self.root)
con.close()
uj5u.com熱心網友回復:
我不明白所有的錯誤,但是當從表中選擇一些東西(在這種情況下是“注冊”)時,你可以通過列出它們來選擇它們,比如:
c.execute("SELECT username, password ... FROM register")
或者您只需選擇所有內容:
c.execute("SELECT * FROM register")
在這種情況下,您兩者都做了(“SELECT username * FROM ...”),這就是可能出現錯誤的原因。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/436100.html
下一篇:react中基于條件的路由
