I've been having a lot of trouble with sell.php. I can sell stocks, that is, they are removed from the stock list but I do not receive the cash from the sale. Also, sale history does not show up on my history of transactions.
I get an error message of undefined index: shares for lines 30 and 36
Relevant code:
//see what stock they have
$stocks = query("SELECT symbol, shares FROM user_portfolio WHERE id = ?",$_SESSION["id"]);
//get number of shares
$number = query("SELECT shares FROM user_portfolio WHERE id = ? and symbol = ?", $_SESSION["id"], $_POST["stock"]);
//get the total value of those shares
$value = $price["price"]*$number["shares"]; (line 30)
//update number of shares
query("DELETE FROM user_portfolio WHERE id = ? AND symbol = ?",$_SESSION["id"], $_POST["stock"]);
//update cash value
query("UPDATE users SET cash = cash + ? WHERE id = ?",$value,$_SESSION["id"]);
$date = date('Y-m-d H:i:s');
query("INSERT INTO history (date, symbol, transaction, shares, id) VALUES(?, ?, ?, ?, ?)",$date,$_POST["stock"],"SELL",$stocks["shares"],$_SESSION["id"]); (line 36)
redirect("index.php");