New to python and even newer to sql and i'm simply trying to check sql for usernames that already exists for a log in program but can't quite figure it out. Here's my code:
def validuser():
cursor.execute("SELECT username FROM OCRflix EXISTS")
if cursor.execute == 0:
print("That username already exists")
else:
print("secure password")
I'm aware of sql injection but this is just practise and wont be used, thanks!
sql = 'select exists(select 1 from OCRflix where username = ? limit 1)'
cursor.execute(sql, (myUsername,));
if cursor.fetchone()[0] == 1:
# username found
pass
else:
# username not found
pass
You can try this
sql = "SELECT username FROM OCRflix WHERE username=?"
result = cursor.execute(sql, (user_input,)
if result:
print("Username already exits")
else:
print("secure Password")
the above program checks if the user input is already present in the username column.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.