0

I am working on pset9 finance and I have been stuck for a while on it, especially this part:

        cash = db.execute("SELECT cash FROM users WHERE user_id = :userid", userid=
        session["user_id"])[0]["cash"]
        price = lookup(request.form.get("symbol"))['price']
        shares = float(request.form.get("shares"))
        symbol = request.form.get("symbol")
        datenotstring = datetime.datetime.now()
        date = datenotstring.strftime("%m/%d/%Y")

        if price*shares > cash:
            return apology("not enough money, can't afford", 400)

It crashes on cash = db.execute("SELECT cash FROM users WHERE user_id = :userid", userid= session["user_id"])[0]["cash"] with the error cash = db.execute("SELECT cash FROM users WHERE user_id = :userid", userid = session["user_id"])[0]["cash"] IndexError: list index out of range

I am unsure of how to fix this, in register I had it add cash to the user's account and that worked fine. Please help. Thanks

0

From the posted code and error message, the logical assumption is that the SELECT query returned no rows.

How is user_id populated? The distro database has no such column. The distro login function sets session["user_id"] to the id column in users table.

You must log in to answer this question.

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