i cannot see any syntax error for several days, so if anything can help is highly appropriated
here is my code :
@app.route("/buy", methods=["GET", "POST"]) @login_required def buy(): """Buy shares of stock""" # User reached route via POST (as by submitting a form via POST) if request.method == "POST": # Ensure symbol was submitted if not request.form.get("symbol"): return apology("must provide symbol", 403) # Ensure shares was submitted shares = int(request.form.get("shares")) if not shares: return apology("must provide shares", 403) if not shares > 0: return apology("must provide positive number of shares", 403)
# Query database for cash
rows = db.execute("SELECT cash FROM users WHERE id = :id",
id = session["user_id"])
cash = float(rows[0]["cash"])
quote = lookup(request.form.get("symbol"))
price = quote["price"]
totalprice = price *shares
company = quote["name"]
# If enough money, execute buy
if not cash or cash < totalprice:
return apology("not enough cash", 403)
# update tables, transction detail
db.execute("INSERT INTO transaction (id, company, shares, price, totalprice) VALUES (:id, :company, :shares, :price, :totalprice)",
id = session["user_id"], company = company, shares = shares, price = price, totalprice = totalprice)
# update table user for the new cash
db.execute ("UPDATE users SET cash = cash - :totalprice WHERE id = :id" , id = session["user_id"], totalprice = totalprice)
# User reached route via GET (as by clicking a link or via redirect)
else:
return render_template("buy.html")
the debug50 error shows: AttributeError: 'RuntimeError' object has no attribute 'name' DEBUG:cs50:SELECT cash FROM users WHERE id = 4 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.iextrading.com DEBUG:urllib3.connectionpool:https://api.iextrading.com:443 "GET /1.0/stock/aapl/quote HTTP/1.1" 200 925 DEBUG:cs50:INSERT INTO transaction (id, company, shares, price, totalprice) VALUES (4, 'Apple Inc.', 1, 209.07, 209.07) ....... RuntimeError: near "transaction": syntax error [SQL: "INSERT INTO transaction (id, company, shares, price, totalprice) VALUES (4, 'Apple Inc.', 1, 209.07, 209.07)"]
i think the value showed here is exact as what i typed in and suppose to be. so in insert line must have syntax error. and if i put this line into SQL in the data file, it does not work as well.