I'm done with pset7 but my sell.php never updates the portfolio table when I sell stocks. it only displays the drop-down menu correctly where it shows the stocks bought in the list, but when i choose a symbol and click sell, i get redirected to portfolio without any change in the stocks nor in the cash value and also doesn't show any transactions in the history table.
Here's my sell.php:
<?php
require("../includes/config.php");
$symbols = query("SELECT * FROM portfolio WHERE id = ?", $_SESSION["id"]);
$totals = [];
foreach ($symbols as $symbol)
{
$totals[] = [
"sellsymbol" => $symbol["symbol"], "sellshares" => $symbol["share"]];
}
if ($_SERVER["REQUEST_METHOD"] !== "POST")
{
render_logged("sell_form.php", ["title" => "Sell", "totals" => $totals]);
}
else if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$s2 = lookup($_POST['symbols']);
$price = ["price" => $s2["price"]];
$s1 = query("SELECT * FROM portfolio WHERE id = ? AND symbol = ?", $_SESSION["id"], strtoupper($_POST['symbols']));
$value[] = ["share" => $s1["share"]];
$costs = $value["share"] * $price["price"];
query("DELETE FROM portfolio WHERE id = ? AND symbol = ?", $_SESSION["id"], strtoupper($_POST['symbols']));
query("INSERT INTO history (id, symbol, shares, transaction) VALUES(?, ?, ?, ?)",$_SESSION["id"], strtoupper($_POST['symbols']), $totals["share"], "SELL");
query("UPDATE users SET cash = cash + ? WHERE id = ?", $costs, $_SESSION["id"]);
redirect("index.php");
}
?>
and here's my sell_form.php:
<form action="sell.php" method="post">
<fieldset>
<div class="form-group">
<select name="symbols" style="width: 90px; padding: 3px;">
<option value="symbols">Symbols</value>
<?php foreach ($totals as $total): ?>
<option value="symbols"><?= $total["sellsymbol"] ?></value>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default" value="sell">Sell</button>
</div>
</fieldset>
can anyone point to me where the mistake can be?
My buy.php file works fine except that cash also doesn't change. but it adds stocks to portfolio and shows the transaction movements in history, unlike sell.php
Thanks a lot in advance!