我想要一個與我制作的注冊資料庫相關的登錄系統
我正在嘗試進行一個復雜的查詢,該查詢需要用戶輸入:
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="*")
Button(self.root,
text="Save",
command=self.login)
按保存時沒有任何反應
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 1 FROM register WHERE username = ? AND password = ?", (self.username.get(), self.password.get()))
result = c.fetchone() # get the record if any
if result:
command=self.invcon() ##A external thing I want to open if the user enters the data in correctly
else:
messagebox.showerror("Error","Incorrect information entered", parent=self.root)
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/qukuanlian/435630.html
