0

What is it? I received error:

"sqlalchemy.exc.ArgumentError: This text() construct doesn't define a bound parameter named 'id'

@app.route("/buy", methods=["GET", "POST"])
@login_required
def buy():
"""Buy shares of stock."""

if request.method == "POST":

    if not request.form.get("search"):
        return apology("must provide sumbol")

    if not request.form.get("number"):
        return apology("must provide number of shares to buy")

    if float(request.form.get("number")) <= 0:
        return apology("number of shares to buy must be a possitive number")

    quote = lookup(request.form.get("search"))

    if not quote:
        return apology("must provide existing company symbol")

    cash = db.execute("SELECT cash FROM users WHERE id= :id", \
        id=session["user_id"])

    if quote["price"] * float(request.form.get("number")) > cash[0]["cash"]:
        return apology("not enough cash to buy ordered number of sheres")

    price= lookup(request.form.get("search"))

    db.execute("INSERT INTO history(user_id, symbol, shares, price, total) VALUES(:user_id, :symbol, :shares, :price, :total)", \
        id= session["user_id"], \
        sumbol= request.form.get("search"), \
        shares= request.form.get("number"), \
        share_price= price["price"], \
        total= (float(request.form.get("number")) * float(price["price"])))

return render_template("buy.html")

I know that my code is not finished but I'm trying step by step.

2

Each bound parameter in the VALUES clause needs a corresponding named parameter passed to execute. (Conversely every passed parameter should have a matching bound parameter). In the INSERT INTO history sql there are several (3) mismatches between bound parameter names and supplied parameters.

You must log in to answer this question.

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