0
def buy():
    """Buy shares of stock"""
    if request.method == "GET":
        return render_template("buy.html")
    else:
        if not request.form.get("symbol"):
            return apology("missing symbol", 400)
        if not request.form.get("shares"):
            return apology("missing shares", 400)
        symbol = request.form.get("symbol")
        shares = float(request.form.get("shares"))
        lis = lookup(symbol)
        cost = float(lis["price"])
        price = cost * shares
        row = db.execute("SELECT * FROM users WHERE id = :id", id = session["user_id"])
        saving = row[0]["cash"]
        if price > saving:
            return apology("can't afford", 400)
        saving = saving - price
        db.execute("INSERT INTO users (cash) VALUES (:cash) WHERE id = :id", cash = saving, id = session["user_id"])
        db.execute("CREATE TABLE IF NOT EXISTS 'tracker' ('id' INTEGER PRIMARY KEY NOT NULL, 'name' TEXT NOT NULL, 'no' INTEGER NOT NULL")
        db.execute("INSERT INTO tracker (id, name, no) VALUES (:id, :name:, :no)", id=session["user_id"], name=symbol, no=int(shares))
        return render_template("test.html", price=row[0]["username"])

error:

RuntimeError: near "WHERE": syntax error
0

INSERTs cannot take WHERE clauses. Looks like you meant to use an UPDATE statment to update the users cash balance.

  • Ah that was silly. Thanks a lot! – Varun Beluguli Aug 24 '20 at 19:12
  • I'm getting a bug from the INSERT line which says incomplete input – Varun Beluguli Aug 24 '20 at 19:28
  • Nvm got it. Thanks! – Varun Beluguli Aug 24 '20 at 19:34

You must log in to answer this question.

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