尝试添加到.db fi时出现Python SQLite错误

2024-04-19 07:32:54 发布

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

运行程序并尝试插入数据时出现以下错误:

'sqlite3.OperationalError: near ")": syntax error'

我的代码如下:

import sqlite3
def insert_data(values):
    with sqlite3.connect("mrsimms.db")as db:
        cursor = db.cursor()
        sql ='Insert into Stock(Name,Type,RetailPrice,NumberInStock,)values(?,?,?,?,?)'
        cursor.execute(sql,values)
        db.commit()

if __name__ == "__main__":
    add = "y"
    while add == "y":
        Name = input("Please enter the Name: ")
        Type = input("Please enter the type of product: ")
        RetailPrice =input("Retail Price: ")
        NumberInStock = input('Please enter the amount in stock: ')
        AddNewStock = (ProductID,Name,Type,RetailPrice,NumberInStock)
        print(AddNewStock)
        insert_data(AddNewStock)
        add = input("Do you wish to add another record? (y/n) ")
        print()

任何帮助都将不胜感激!你知道吗


Tags: thenameaddinputdbtypesqlite3cursor