Why does the fetchone() return None when onLogin() is called, even though the database has a row with a value? When I use the same query in the sql database it returns the correct value. Using fetchall() and using a for loop with it returns nothing on the terminal.
import mysql.connector
#SQL CONNECTION
db = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="python"
)
cursor = db.cursor(buffered=True)
#main
def onStart():
global username
print("Enter a username to continue")
username = input()
#Checking the database for the username
query = "SELECT username FROM userdata"
cursor.execute(query)
result = cursor.fetchall()
for x in result:
if x == (username,):
onLogin()
else:
print("Error Occurred!")
def onLogin():
print("Enter a password")
password = input()
#comparing pwds
query = "SELECT password FROM userdata WHERE username = '%s'"
cursor.execute(query, username)
result = cursor.fetchone()
print(result)
onStart()