I am working on building a textbook auction application using the Python MySQL module to connect to the database. The login code isn't working. When prompted, I type in a username/password that I know is in the DB, but it keeps saying that the username/password is invalid. Am I using the cursor object incorrectly?
#import the datetime package to use dates
import datetime
#import the mysql connector to access the database
import mysql.connector
#establish a connection to the database
cnx = mysql.connector.connect(user='uXXXXXX', password='pXXXXXX',
host='COMPDBSXXX', database='schemaXXXXXX')
#retrieve a cursor to execute queries
cursor = cnx.cursor()
logged_in = False
########----USER INTERFACE STARTS HERE----###################
print("Welcome to eGCC! Please select an action.")
print("\r")
print("1. LOGIN")
###---LOGIN----#################
while logged_in == False:
print("Enter eGCC username: ")
username = input()
print("Enter eGCC password: ")
password = input()
query = ("SELECT Username from egccuser")
cursor.execute(query)
for ID in cursor:
if ID == str(username):
userID = username
query = ("SELECT password from egccuser where Username = %s")
qdata = str(userID)
cursor.execute(query,qdata)
if cursor == password:
logged_in = True
if logged_in == False:
print("Error: Invalid Username/Password")
#close cursor
cursor.close()
#close the connection to the DBMS
cnx.close()