1 回答

TA貢獻2003條經驗 獲得超2個贊
您可以使用語句來檢查從條目中獲取的電子郵件是否在數據庫中。像這樣:SELECT
def checkEmailExistance():
email_exists = False
c.execute('SELECT * FROM email WHERE <email adresses column> = :email_adress'
{"email_address": user_email.get()})
# Previous line selects a row of your database only if the column that contains
# the email adress in said row has the same adress as the one from the entry
if c.fetchone() # which is the same as saying "if c.fetchone retrieved something in it"
email_exists = True
else:
email_exists = False
return email_exists
此外,我不必使用變量,而只需返回 True 或 False 來縮短代碼,我以這種方式編寫它以提高可讀性。email_exists
編輯這與您的問題無關,但是在使用數據庫時,我發現在每個自動加載和更新的表的開頭添加一個“value_id”列非常有用,您永遠不知道何時需要它!
添加回答
舉報