Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用变量Python sqlite更新表中的记录_Python_Sql_Database_Sqlite - Fatal编程技术网

使用变量Python sqlite更新表中的记录

使用变量Python sqlite更新表中的记录,python,sql,database,sqlite,Python,Sql,Database,Sqlite,遇到以下问题: def CheckUpdateUser(self, usernameC, passwordC, usernameE, passwordE, edit_account_window): usernameC = usernameC.get() passwordC = passwordC.get() usernameE = usernameE.get() passwordE = passwordE.get() if len(usernameC)

遇到以下问题:

def CheckUpdateUser(self, usernameC, passwordC, usernameE, passwordE, edit_account_window):
    usernameC = usernameC.get()
    passwordC = passwordC.get()
    usernameE = usernameE.get()
    passwordE = passwordE.get()
    if len(usernameC) == 0:
        messagebox.showinfo("Error", "Please Enter Current Credentials. \n\nIf issue persists contact an Admin or try again.")
    elif len(usernameE) == 0:
        messagebox.showinfo("Error", "Please Enter New Credentials. \n\nIf issue persists contact an Admin or try again.")
    else:
        with sqlite3.connect("library.db") as db:
            cursor = db.cursor()
            cursor.execute("SELECT password from loginUsers WHERE username = ? and password = ?", (usernameC, passwordC))
            username_search = cursor.fetchone()
            if not username_search is None:
               # self.updateUserInDatabase
                cursor.execute("UPDATE loginUsers SET username = ? and password = ? WHERE username = ?", (usernameE, passwordE, usernameC))                      
                messagebox.showinfo("Success!", "Credentials updated, you can now go back to login page and use the credentials you entered")        
            else:
                messagebox.showinfo("Error.", "User Not Found. \n\nContact an Admin to register an account or try again.")
第节,我在Python中使用tkinter,我试图用新的用户信息(用户名和密码(usernameE,passwordE))更新当前用户信息(用户名和密码(usernameC,passwordC))

usernameC和passwordC都是用户在代码的另一部分输入的:

        with sqlite3.connect("library.db") as db:
            cursor = db.cursor()
            cursor.execute("SELECT password from loginUsers WHERE username = ? and password = ?", (usernameC, passwordC))
            username_search = cursor.fetchone()
            if not username_search is None:
               # self.updateUserInDatabase
                cursor.execute("UPDATE loginUsers SET username = ? and password = ? WHERE username = ?", (usernameE, passwordE, usernameC))                      
                messagebox.showinfo("Success!", "Credentials updated, you can now go back to login page and use the credentials you entered")        
在检查usernameC和passwordC是否在loginUsers表中之后,我想用usernameE和passwordE更新usernameC和passwordC


请帮忙!!

A)使用ORM。B) 不要编写自己的身份验证系统。好的是一毛钱一打C)桌面应用程序还需要用户名密码吗?@e4c5这是一个编程项目,我们需要使用我们自己的作为上面的一个,我如何使上面的代码工作?谢谢你忘了提什么麻烦事了was@e4c5输入的usernameC和passwordC(与数据库“library.db”中loginUsers表中记录的用户名和密码匹配)不要使用usernameE和passwordE更新,我希望输入的usernameC和passwordC更新为usernameE和passwordpasswordE@RobertoMiguelPimentel,您是否在
更新
查询后尝试执行
提交
    Label(edit_account_window, text='Current Username: ', bg = self.bgc, fg = "grey", font = "Arial").place(x=315, y=217)
    Label(edit_account_window, text='Current Password: ', bg = self.bgc, fg = "grey", font = "Arial").place(x=315, y=237)         
    Label(edit_account_window, text='New Username: ', bg = self.bgc, fg = "grey", font = "Arial").place(x=315, y=257)
    Label(edit_account_window, text='New Password: ', bg = self.bgc, fg = "grey", font = "Arial").place(x=315, y=277)

    usernameC = StringVar()
    passwordC = StringVar()

    usernameE = StringVar()
    passwordE = StringVar()

    Entry(edit_account_window, textvariable = usernameC, bg = 'light grey').place(x=450, y=220)
    Entry(edit_account_window, show='*', textvariable = passwordC, bg = 'light grey').place(x=450, y=240)
    Entry(edit_account_window, textvariable = usernameE, bg = 'light grey').place(x=450, y=260)
    Entry(edit_account_window, show='*', textvariable = passwordE, bg = 'light grey').place(x=450, y=280)

    edit_account_window_back = Button(edit_account_window, text=('Back'), width = 6, height = 1, bg = 'light grey', fg = 'black', font = ('Arial', 10), command=lambda:self.display(main_window))
    edit_account_window_back.place(x=27, y=750)

    updateB = Button(edit_account_window, text='UPDATE INFO', width = 11, command=lambda:self.CheckUpdateUser(usernameC, passwordC, usernameE, passwordE, main_window)) # This makes the register button, which will go to the CheckRegister def.
    updateB.place(x=472, y=300)