Python Forum

Full Version: Inserting values from multiple lists sqlite
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
  for item1, item2 in cartproducts, cartprices:
        c.executemany("INSERT INTO orders(Product_Name, Product_Price) VALUES(?, ?);", (item1, item2, ))
   connection.commit()
I'm currently having issues inserting values from two different lists to my database. I've got the code working for just adding values from one list, but I'm stumped on how to use a second. I need to add the Product Name and Prices together or they just end up separated. Right now I'm getting the error ValueError: too many values to unpack (expected 2) and I'm not sure what the fix is.
I do not know how sqlite works. And you don't give information on your datastructures. But I guess cartproducts and cartprices are lists. So I think you will have to zip those together.
for item1, item2 in zip(cartproducts, cartprices):
      c.executemany("INSERT INTO orders(Product_Name, Product_Price) VALUES(?, ?);", (item1, item2, ))
 connection.commit()
(untested)