John Dow
John Dow

Reputation: 47

Web2Py insert into database error

I am trying to make insert. This is my code:

db.define_table('orders',
            Field('idProduct', type = 'integer'),
            Field('quantity', type = 'integer'),
            Field('idUser', type = 'integer'),
            Field('status'),
            Field('order_date'),
            Field('product_price', type = 'integer'))

The SQL:

sql = "Insert into orders (idProduct,idUser,quantity,status,order_date,product_price) values "
sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," + str(quantity) + ",'cart','" + str(order_date)+ "," + str(product_price)+"')"

and I am getting following error:

<class 'sqlite3.OperationalError'> 5 values for 6 columns

I don't understand what is wrong, because if i remove product_price, everything is working.

Thanks.

Upvotes: 0

Views: 52

Answers (1)

CodeFuller
CodeFuller

Reputation: 31312

You have extra quote before the last closing bracket. Remove it and it will fix the error:

sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," +
str(quantity) + ",'cart','" + str(order_date)+ "," +
str(product_price)+")"

Upvotes: 1

Related Questions