使用SQLite 3和Python時'raw_input'的主要問題

2024-04-20 15:39:22 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的数据库中,我使用raw_input来允许用户向数据库中输入数据,问题是我给每个数据记录分配了一个ID,这是表的主键。在

username = raw_input("What would you like your username to be? ")
email = raw_input("What is your email address? ")
firstName = raw_input("What is your first name? ")
surname = raw_input("What is your surname? ")
age = raw_input("How old are you? ")
password = raw_input("What is your password?") #Encryption method will be added later
age = int(age) #Changing the age variable into an integer so it can be inputted into the database

#DB part
conn = db.connect('apollo.db') #Connecting to the database
cursor = conn.cursor()
cursor.execute("INSERT INTO users VALUES(?, ?, ?, ?, ?, ?)",
            (username, email, firstName, surname, age, password)) #Inserting the user's data into the table

conn.commit() #Committing the changes

conn.close() #Closing the connection

我假设因为主键会自动递增,所以不需要将它添加到代码中,因为每个记录都会自动获得一个数字。问题是,当我回答完所有raw_input问题时,会收到以下错误消息:

^{pr2}$

有什么我需要添加到主键的代码中吗?在


Tags: theinputageyourrawisemailusername