I'm working on sell, and I ran into trouble in one of my db.execute statements. For whatever reason, in the previous line, it was perfectly fine using stock["price"] but in my second db.execute, it crashes and gives me an internal server error. Here is my code and thank you for your help
def sell():
"""Sell shares of stock"""
#return apology("TODO")
# PDHTEFW7T4KOTDHI
if request.method == "POST":
shares = float(request.form.get("shares"))
stock = lookup(request.form.get("symbol"))
#stockprice = stock['price']
if not stock:
return apology("Invalid Symbol")
if shares <= 0:
return apology("shares must be > 0")
db.execute("UPDATE users SET cash = cash + :amount WHERE id = :userID", amount=int(shares) * stock["price"], userID=session["user_id"])
db.execute("INSERT INTO transactions (userID, symbol, shares, amount, stockprice) VALUES (:userID, :symbol, :shares, :amount, stockprice)", userID=session["user_id"], symbol = stock, shares = shares, amount = int(shares) * stock["price"], stockprice = stock["price"])
return apology("good")
else:
return render_template("sell.html")