Right now I'm attempting to insert some information from the user's transaction into my table with this code:
# Record transaction
db.execute("INSERT INTO trading buyer = :buyer, ticker = :ticker, price = :price, date = :date ", buyer=session["user_id"], ticker=buy["symbol"], price=buy["price"], date=now)
Now the really odd part is that on the terminal, it shows all the values being correctly inserted but I'm still getting an error nonetheless, and the table isn't actually updating.
I'm not really sure how to read this. How can the syntax be wrong if all the values are being correctly inserted?
Some related code:
shares = request.form.get("shares")
result = db.execute("SELECT cash FROM users WHERE id = :id", id=session["user_id"])
shares = float(shares) # Convert shares to float for math
if result[0]["cash"] >= buy["price"] * shares: # Check if user has enough cash
# Updates user's funds
db.execute("UPDATE users SET cash = :cash WHERE id = :id", id=session["user_id"], cash=result[0]["cash"] - buy["price"] * shares)
now = datetime.datetime.now()
Additional errors: File "/home/ubuntu/workspace/pset7/finance/helpers.py", line 34, in decorated_function
return f(*args, **kwargs)
File "/home/ubuntu/workspace/pset7/finance/application.py", line 91, in buy
date=now)
File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/cs50/sql.py", line 224, in execute
raise e
RuntimeError: near "'AAPL'": syntax error [SQL: "INSERT INTO trading (\n buyer,\n ticker,\n price,\n date)\n VALUES\n (\n 4\n 'AAPL'\n 186.05\n '2018-05-09')"] (Background on this error at: http://sqlalche.me/e/e3q8)