I have a problem as in here: pset7 sell controller issue: undefined index.

I made a new thread because that one's a year old. I hope this one won't get marked as a duplicate and get closed for it.

Anyway, I have my code on Pastebin in these two links: pastebin.com/rs6TBEJu (sell.php, selling_form.php and sell_stock.php) and pastebin.com/KXSxeESE (index.php and portfolio.php).

I hope someone on here can help me out here. Thanks in advance.

Edit: Because CliffB's question, I'll add more information here now.

The errors I'm getting are on sell_stock.php which is the controller that my selling form (selling_form.php) submits to, and they read as follows:

Notice: Undefined index: symbol in /home/ubuntu/workspace/pset7/public/sell_stock.php on line 7

Notice: Undefined index: shares in /home/ubuntu/workspace/pset7/public/sell_stock.php on line 15

On the database, the portfolios table is called as "portfolios". There are four fields, namely "id", "user_id", "symbol" and "shares". I followed the specifications' advice on what fields should be Unique and which should be the Primary Key.

I hope that's enough info.

  • Can you be more specific? You've listed 3 different php files. What errors are you getting? What files are causing the error? Can you also add the description(s) of the tables and indexes in the database as well?
    – Cliff B
    Dec 26, 2016 at 11:34
  • I'll edit the original post, then. Thanks for pointing that out. Dec 26, 2016 at 12:18
  • Done editing from a while ago. The details are now there. Thanks in advance for any help. Dec 26, 2016 at 16:35
  • you need to read this: cs50.stackexchange.com/a/22335/13557 And then look again at these lines: $total_cash = $stock["price"] * $shares["shares"]; $delete_from_portfolios = CS50::query("DELETE FROM portfolios WHERE user_id = ? AND symbol = ?", $_SESSION["id"], $shares["symbol"]); Dec 26, 2016 at 17:17
  • Okay, I tried making some changes and now I have this: pastebin.com/rs6TBEJu. Now I have an "Undefined offset" error on lines 7 and 15. Dec 26, 2016 at 17:58


You must log in to answer this question.

Browse other questions tagged .