0

So when I try to make a history table, with some code that looks like

 purchases = db.execute("SELECT stock, boughtsold, price, shares, time, user_id FROM history WHERE user_id = :user_id")

    for purchase in purchases:
        stock = purchase["stock"]
        boughtsold = purchase["boughtsold"]
        price = purchase['price']
        shares = purchase['shares']
        time = purchase['time']
        userid = purchase["user_id"]

#else:

    #stock = lookup(request.form.get("symbol"))
    return render_template("history.html", stock=stock, boughtsold=boughtsold, price=price, shares=shares, time=time, userid=userid)

and html of

{% for purchase in purchases %}

        <tr>
            <td>{{purchase.boughtsold}}</td>
            <td>{{purchase.stock}}</td>
            <td>{{purchase.price}}</td>
            <td>{{purchase.shares}}</td>
            <td>{{purchase.time}}</td>
            <td>{{purchase.userid}}</td>
        </tr>

    {% endfor %}

I get an error message with

 File "/home/ubuntu/ide50/workspace/pset8/finance/application.py", line 162, in history
purchases = db.execute("SELECT stock, boughtsold, price, shares, time, user_id FROM history WHERE user_id = :user_id")
File "/usr/local/lib/python3.7/site-packages/cs50/flask.py", line 40, in _execute_after
return _execute_before(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/cs50/sql.py", line 177, in execute
raise RuntimeError("missing value for placeholder (:{})".format(name))
RuntimeError: missing value for placeholder (:user_id)

I'm not sure why this would be a problem. Where is the error? And how can I fix it? thanks for any help

1

That's happening in the first line of code you showed. The db.execute is missing a named argument, something like

db.execute("... WHERE user_id = :user_id", user_id=session["user_id"])
                                 ^^^^^^^ = ^^^^^^^ these two are same

The rest of the code does not make too much sense to me, as you would render the template for a single transaction, but I guess you don't show the actual code there, as render_template call and jinja template don't seem to match.

You must log in to answer this question.

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