I've been trying to make the following code work but have not found a way. Im new to Python and know a little of MySQL. Connecting Python with MySQL is something I recently learned for my college project.
import mysql.connector
password = input("Enter Password Here")
print(password)
conn2 = mysql.connector.connect(host="localhost", user="root", password="root", database="trial")
c2 = conn2.cursor()
c2.execute("select lastname from table1 where lastname= '?' ", (password))
row1 = c2.fetchone()
print(row1)
if(c2==password):
print("Welcome User")
else:
print("Invalid")
My connection with the database is working just fine and the SQL statements are also executing as expected. The only problem is that when inserting the password
variable. The print(row1)
code outputs None
in the Console. Please Help