I am creating a web-based POS system. Once the users clicks the "order submit" data is submitted via this schema:
CREATE TABLE orders (
transaction_id integer primary key autoincrement,
total_price integer not null
);
CREATE TABLE order_items (
transaction_id integer REFERENCES orders(transaction_id),
SKU integer not null,
product_name text not null,
unit_price integer not null,
quantity integer not null
);
Through this flask code:
@app.route('/load_ajax', methods=["GET", "POST"])
def load_ajax():
if request.method == "POST":
data = request.get_json()
for group in groupby(data, itemgetter('name')):
id, data_list = group
for d in data_list:
print d['subtotal']
db = get_db()
db.execute('insert into order_items (SKU, product_name, unit_price, quantity) values (?, ?, ?, ?); insert into orders (total_price) values (?)',
[d['sku'], d['name'], d['price'], d['quantity']],[d['subtotal']])
db.commit()
return jsonify(location=url_for('thankyou'))
I am getting a 500 error and I'm not sure why it is happening. Do I need to do two different db.execute statements?