0

Trying to add functionality to modify number of shares.

This won't work:

num_sell = request.form["num_sell"]
db.execute("UPDATE purchases SET shares=num_sell WHERE order_num=1")

"RuntimeError: (sqlite3.OperationalError) no such column: num_sell [SQL: 'UPDATE purchases SET shares=num_sell WHERE order_num=1']"

This does work (but it obviously useless because the # needs to change):

db.execute("UPDATE purchases SET shares=5 WHERE order_num=1")
4
  • You need to bind the variables. (shares = :num_sell) May 8 '17 at 19:07
  • "RuntimeError: Bind parameter 'num_sell' without a renderable value not allowed here." May 8 '17 at 19:17
  • please show the code May 8 '17 at 19:20
  • num_sell = request.form["num_sell"] db.execute("UPDATE purchases SET shares=:num_sell WHERE order_num=1") May 8 '17 at 19:23
1

If you don't use bound variables with the CS50 sql module, sqlite will read num_sell as a column name, thus the "no such column" error. You need to use bound variables ostensibly to prevent sql injection. Review the last 30 seconds of the register walkthrough for sample syntax, or the login function in application.py.

1
  • I reviewed the login function and that was the answer. May 9 '17 at 2:58

You must log in to answer this question.

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