When I try to insert the portfolio values into the SQL database I receive an internal server error, please can someone tell me what I'm doing wrong.
if request.method == "POST":
# ensure symbol field isn't blank
if not request.form.get("symbol"):
return apology("must provide symbol", 403)
# ensure shares field isn't blank
elif not request.form.get("shares"):
return apology("must provide amount", 403)
# check validity of amount
try:
amount = int(request.form.get("shares"))
except:
return apology("please provide integer")
# check validity of symbol
if lookup(request.form.get("symbol")) == None:
return apology("invalid symbol")
else:
quote = lookup(request.form.get("symbol"))
# calculate total price
total = quote["price"]*amount
cash = db.execute("SELECT cash FROM users WHERE id = :id", session["user_id"])
# check if user has sufficient cash
if(cash >= total):
db.execute("INSERT INTO portfolio (id, price, number, symbol, when) VALUES (:id, :price, :number, :symbol, datetime('now'))", session["user_id"], quote["price"], amount, quote["symbol"])
else:
return apology("insufficient cash for chosen stock")
return render_template("buy.html")
else:
return render_template("buy.html")