0

why I get this error RuntimeError: (sqlite3.OperationalError) near "'$59.31'": syntax error [SQL: "INSERT INTO portfolio (id, symbol, shares, price) VALUES(2, 'A', 1, '$59.31'"]

here is my code:

@app.route("/buy", methods=["GET", "POST"])
@login_required
def buy():
"""Buy shares of stock."""
if request.method == "POST":
    if not request.form.get("symbol"):
        return apology("MISSING SYMBOL")

    if not request.form.get("shares"):
        return apology("PROVIDE NUMBER OF SHARES")

    symbol = lookup(request.form.get("symbol"))
    if not symbol:
        return apology("INVALID SYMBOL")

    try:
        shares = int(request.form.get("shares"))
    except:
        return apology("INVALID SHARES")

    total = shares * symbol["price"]
    row = db.execute("SELECT cash FROM users WHERE id = :id", id = session["user_id"])
    if row[0]['cash'] < total:
        return apology("CAN'T AFFORD")

    db.execute("INSERT INTO portfolio (id, symbol, shares, price) VALUES(:id, :symbol, :shares, :price",
    id = session["user_id"], symbol = symbol["symbol"], shares = shares, price = usd(symbol["price"]))

    db.execute("UPDATE users SET cash = cash - total WHERE id = :id", id = session["user_id"])

    return redirect(url_for("index"))
else:
    return render_template("buy.html")

any help please, thanks.

0

You have missed a 'closing parenthesis ' ) after '$59.31'.

You must log in to answer this question.

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