0

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: enter image description here

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:

enter image description here

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.

3
  • Can you answer a few questions for more clarity? When the code executes, does the insert appear to work, or does it print the apology message? If it doesn't print the aploogy message, have you looked at the history table data both before and after running the query? What, if anything is different?
    – Cliff B
    Sep 1, 2015 at 19:18
  • @CliffB please see my edit-- is it more helpful? Sep 1, 2015 at 22:20
  • Is it possible that your insert query is missing any required fields? like maybe shares?
    – Cliff B
    Sep 1, 2015 at 22:36

3 Answers 3

1

Try checking your index+ link on the Structure view. I deleted all my unique and primary keys, as well as any links to other tables. This solved the problem..thanks to Kareem .. and, I apologise for submitting a comment as an answer earlier. Frustrated newbie here, not paying attention!

1
  • I don't have a table called index; i have a database called pset7 and tables called users, portfolio, and history. What are you referring to here, and do you reinsert thee keys and links afterward? Sep 6, 2015 at 1:31
0

Any field that is not allowed to be NULL must be populated by your query for the query to actually work. Be sure that you have every field. Looks like you are missing shares.

1
  • Unfortunately, this isn't working. I populate shares in sell and now I get the "Something went wrong" apology, although I have several print statements for debugging and they work. Sep 3, 2015 at 17:38
0

uncheck primary key for your id field

You must log in to answer this question.

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