I am actually a student trying to build a login/registration functionality within my project. I'm receiving errors in fetching an entire row from mysql which matches the tuple of input-based variables specified in Python and am unsure how to proceed.
In detail: so my intent is to take input from the user in the form of a username and a password and then match it to preexisting rows in a table in MySQL. but my code does not seem to work.
Here is the code:
cursor.execute("SELECT * FROM user WHERE username, password LIKE '%s','%s'"%(username,password))
ecreds = cursor.fetchall()
if len(ecreds) == 1:
print("Login successful. Welcome, ")
Can anyone tell me where I'm going wrong? Any advice is appreciated, thanks.
Can anyone tell me where I'm going wrong? Any advice is appreciated, thanks.
That's not how you compare two columns. Compare each of them and combine with
AND.Also, use a prepared statement rather than string formatting to substitute variables in SQL. See How to use variables in SQL statement in Python?