0

I am struggling with writing data to database when user buys stocks. After code execution no new insertions appears in database and no error messages appears. Also how to get current user name to link transactions with user actions?

        stock = lookup(request.form.get("symbol"))

        name = str(stock['name'])
        symbol = str(stock['symbol'])
        price = float(stock['price'])
        quantity = int(request.form.get("shares"))
        user = 1

        db.execute("INSERT INTO transactions (symbol, quantity, transacted) VALUES(:symbol, :quantity, :transacted)", symbol = symbol, quantity = quantity, transacted = (float(price) * int(quantity)))
0

One thing to check is that there can only be 1 Primary Key. So if a person buys two stocks, you can't have two lines with 1 for userid where it is the Primary Key. Does this makes sense? So you either have to set no Primary Key or do some research on how you can make two parameters combined to be Primary. To get the program to work, temporarily, just redo the database transactions to have no primary key and see if you get it to write to it.

2
  • Thank you, it helped! – Austris Apr 16 '17 at 20:04
  • Great. However, to be strictly correct, you would need to combine two parameters to establish a new Primary Key. For now, just get it to run but return to this when you have time. – cfdphd Apr 16 '17 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .