python的新手,甚至更新的sql和我只是试图检查sql是否存在已登录程序的用户名但却无法弄明白。这是我的代码:
def validuser():
cursor.execute("SELECT username FROM OCRflix EXISTS")
if cursor.execute == 0:
print("That username already exists")
else:
print("secure password")
我知道sql注入,但这只是练习而不会被使用,谢谢!
答案 0 :(得分:0)
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
答案 1 :(得分:0)
你可以试试这个
sql = "SELECT username FROM OCRflix WHERE username=?"
result = cursor.execute(sql, (user_input,)
if result:
print("Username already exits")
else:
print("secure Password")
上述程序检查用户输入是否已存在于用户名栏中。