import easygui as eg
import sqlite3``
conn = sqlite3.connect('ATM.sqlite')
print("Connected to database successfully")
conn.execute("CREATE TABLE if not exists CUSTOMER(ID INTEGER, Name TEXT, Address TEXT, Mobile_no INTEGER, PIN INTEGER, Balance INTEGER)")
def Admin_AddUser():
options = ['ID', 'Name', 'Address', 'Mobile No.', 'PIN']
Current_bal = 0
value = eg.multenterbox('Enter the information for new user', 'Add User', options)
conn.execute('INSERT INTO CUSTOMER (ID, Name, Address, Mobile_no, PIN, Balance) VALUES'
'( value[0],value[1],value[2],value[3],value[4],int(Current_bal))')
我希望在客户表中输入详细信息。但它向我显示以下错误。
sqlite3.OperationalError: near "[0]": syntax error
答案 0 :(得分:1)
data = [value[0],value[1],value[2],value[3],value[4],int(Current_bal)]
cursor.execute('INSERT INTO CUSTOMER (ID, Name, Address, Mobile_no, PIN, Balance) VALUES ( ?,?,?,?,?,?)', data)
答案 1 :(得分:1)
使用参数:
conn.execute('INSERT INTO CUSTOMER (ID, Name, Address, Mobile_no, PIN, Balance)
VALUES (?,?,?,?,?,?)',
[value[0],value[1],value[2],value[3],value[4],int(Current_bal)])