我正在对SQLITE数据库创建一个register方法,但我一直得到这个ValueError:ValueError: operation parameter must be str
代码如下:
import sys
import os
from os import environ
import utils.messages as m
import sqlite3
con = sqlite3.connect('data.db')
cursor = con.cursor()
def login(con):
print("Welcome to your dashboard.")
s.sleep(0.5)
print("Do you want to login [l] or register [r]?")
log_reg = input("> ")
if log_reg == "l":
username = input("Username: ")
password = input("Password: ")
cursor.execute(f"SELECT 1 FROM USERDATA WHERE USERNAME = ? AND PASSWORD = ?", (username, password))
user_exists = cursor.fetchone() is not None
if not user_exists:
print("Username/password combination not found!")
sys.exit(1)
print(f"Hi, {username}!")
pass
elif log_reg == "r":
s.sleep(0.7)
print("What will your username be?")
registerUsername = input("> ")
s.sleep(0.7)
print("What will your password be?")
registerPassword = input("> ")
cursor.execute('''SELECT USERNAME FROM USERDATA WHERE USERNAME = ?''', (registerUsername,))
user_exists2 = cursor.fetchone() is not None
if user_exists2:
s.sleep(0.7)
print("This username is already in use!")
exit()
elif not user_exists2:
sql = ''' INSERT INTO USERDATA(USERNAME, PASSWORD)
VALUES(?,?); ''', (registerUsername, registerPassword)
cursor.execute(sql)
con.commit()
s.sleep(0.7)
print("Succesfully registered!")
s.sleep(0.7)
print("Restart the CLI to log in.")
cursor.close()
exit()
我一直在第52行(cursor.execute(sql)
)上看到错误。有人能帮我吗?在cursor.execute('sql')
中使用字符串也没有帮助。我在谷歌上搜索了很多东西,但都没有答案
编辑:@或Y
sql = f''' INSERT INTO USERDATA(USERNAME, PASSWORD)
VALUES({registerUsername},{registerPassword}); '''
cursor.execute(sql)
con.commit()
s.sleep(0.7)
print("Succesfully registered!")
s.sleep(0.7)
print("Restart the CLI to log in.")
cursor.close()
exit()
替换:
与:
相关问题 更多 >
编程相关推荐