On pset7 and struggling with the history part.
When I buy or sell a stock, it's reflected in the portfolio and the cash available is also updated. However, it does not seem to be affecting the history table at all.
I was on slack discussions that helped me with a lot of things, but the person on slack was unable to see anything wrong with my INSERT SQL statement that would prevent it from writing to the history
table.
This is the statement in sell.php
(I imagine it would be largely similar in buy.php
)
$result = query("INSERT INTO history (id, transaction, symbol, price) VALUES (?, ?, ?, ?)", $_SESSION["id"], $transaction, $_POST["symbol"], $stockprice["price"]);
if ($result === false)
{
apologize("Something went wrong");
}
I've used echo
to view all of these variables and arrays, and they print what I expect.
This is the structure of my history
table:
The person on the slack channel suggested that I ask here because we were both stumped on this.
EDIT:
When I attempt to buy, I do not get an apology. My portfolio updates with the stock I bought, the appropriate number of shares, and the appropriate price per share; the total value is accurately removed from my current balance.
Before doing this, my history table had one transaction record, from a previous test. I have subsequently sold that stock and my portfolio was accurately showing as empty, but the selling was not reflected in the table.
This is how the history table still looks, unchanged:
To sum it up, I bought IBM stock, but then I sold IBM stock and bought AAPL stock, etc. but only the first transaction shows. I created a transaction_id
field that auto-increments specifically so this wouldn't happen.