Python 有没有一种方法可以通过变量从mysql获取数据,并能够在登录系统的if语句中使用它
在select语句中,我需要根据用户输入从数据库中的数据表中选择用户名和密码,输入是从userget和passget变量检索的。我知道它从用户名和密码表中获取所有数据,但我不确定如何使它只获取用户输入的数据Python 有没有一种方法可以通过变量从mysql获取数据,并能够在登录系统的if语句中使用它,python,mysql,tkinter,Python,Mysql,Tkinter,在select语句中,我需要根据用户输入从数据库中的数据表中选择用户名和密码,输入是从userget和passget变量检索的。我知道它从用户名和密码表中获取所有数据,但我不确定如何使它只获取用户输入的数据 def loginpage(): def login(): userget = textinput.get() passget = textinput2.get() usercheck = mycu
def loginpage():
def login():
userget = textinput.get()
passget = textinput2.get()
usercheck = mycursor.execute("SELECT `username` FROM `data`")
u = mycursor.fetchall()
print(str(u))
passcheck = mycursor.execute("SELECT `password` FROM `data`")
p = mycursor.fetchall()
print(str(p))
if u == userget and p == passget:
correctscreen = Tk()
correctscreen.configure(background='yellow')
correctscreen.title("Correct")
correctscreen.geometry("300x200")
labelc = Label(correctscreen, text="Successfully logged in!")
labelc.pack()
buttonc = Button(correctscreen, text="Ok", command=correctscreen.destroy)
buttonc.pack()
url = 'https://thepugweb.epizy.com/login.html'
buttonc1 = Button(correctscreen, text="Ok", command=webbrowser.open(url))
else:
incorrectscreen = Tk()
incorrectscreen.configure(background='pink')
incorrectscreen.title("Incorrect Details")
incorrectscreen.geometry("300x200")
labeli = Label(incorrectscreen, text="Incorrect Details Entered")
labeli.pack()
buttoni = Button(incorrectscreen, text="Close", command=incorrectscreen.destroy)
buttoni.pack()
您可以使用一条SQL语句来获取所需内容: def登录页面: def登录: userget=textinput.get passget=textinput2.get mycursor.Execute从'data'中选择1,其中'username`=%s和'password`=%s,userget,passget rows=mycursor.fetchall 如果是行: 登录成功 ... 其他: 登录失败 ...
你的代码有两个问题:第一个命令=webbrowser.openurl应该是command=lambda:webbrowser.openurl,第二个你从来没有调用buttonc1.pack。当我在buttonc1变量的末尾使用.pack时,它会在以后的函数中返回一个错误,但是当我以没有问题的方式使用它时,我已经更改了webbrowser.open语句。哦,我脑子里的button变量是错误的,但是buttonc1应该已经被删除了,所以打包它是没有用的,因为我现在要删除它。TypeError:“>”在“NoneType”和“int”的实例之间不受支持是我现在得到的错误。你使用哪个模块连接MySQL?我使用xampp控制面板。我的意思是Python模块。无论如何,答案更新了。