Reputation: 55
I try to create a validator by getting data from MySQL. After getting data from MySQL, I have a list containing 2 tuples. But when I tried to printing elements in tuples, instead of printing elements from the tuple, my code printed the letter of each of them. Here is my code:
from tkinter import *
from tkinter import messagebox
from mysqlconnect import my_connect
from mysqlconnect import my_cursor
mysql_get_all_user_information_query = "SELECT user_name, user_password FROM USER_INFORMATION"
my_cursor.execute(mysql_get_all_user_information_query)
all_information_record = list(my_cursor.fetchall())
def validator_username_password():
global all_information_record
username = entry_username.get()
password = entry_password.get()
if username == "" and password == "":
messagebox.showinfo("", "Blank Field Are Not Allowed")
for user_record in all_information_record:
for user_name_pass in user_record:
print(user_name_pass[0])
print(user_name_pass[1])
if username == user_name_pass[0] and password == user_name_pass[1]:
messagebox.showinfo("", "Login Success")
root.destroy()
else:
messagebox.showinfo("", "Incorrent Username and Password")
Here is the output (I have account1: admin, password: 123456
and account2: admin123, password: 123456):
Thank all of you so much!!!
Edit: When I use only 1 for loop, I get 2 tuples.
Upvotes: 1
Views: 197
Reputation: 15098
You explained your situation in the comments yourself. You are no longer having tuples, but you are still indexing it. IMO, you do not need nested loops(even proves your logic wrong), here is an example on checking username and password(non-tkinter
example):
lst = [('u1','p1'),('u2','p2')]
def login():
for item in lst:
u_name = item[0]
p_name = item[1]
if u_name == username and p_name == password:
print('Successfully logged in')
break
else:
print('Wrong credential')
break
username = 'u1'
password = 'p1'
login()
Upvotes: 1