2
我有2頁sell.php和sell_form.php。當用戶從sell_form.php的下拉菜單中選擇一個股票代碼時,我在sell.php中有一個查詢,它應該從數據庫中刪除該股票代碼,但是我現在正在獲取的只是一個空白頁面我點擊賣按鈕。我不確定我完全理解下拉菜單中的值是如何傳遞給sell.php表單的。這是我的代碼至今無法刪除數據庫中的行php
這是我的sell.php文件
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// delete the stock from their portfolio
query("DELETE FROM shares WHERE id = ? AND symbol = ?", $_SESSION["id"],$_POST["symbol"]);
redirect("/");
}
else
{
$rows = query("SELECT * FROM shares WHERE id = ?", $_SESSION["id"]);
//create array to store the shares
$shares = [];
//for each of the user info
foreach($rows as $row){
//lookup stock info
$stock = lookup($row["symbol"]);
if($stock !== false){
$shares[] = [
"name" => $stock["name"],
"price" => $stock["price"],
"shares" => $row["shares"],
"symbol" => $row["symbol"],
"total" => $row["shares"]*$stock["price"]
];
}
}
// render portfolio
render("sell_form.php", ["shares" => $shares, "title" => "Sell"]);
}
這是我sell_form.php
<form action="sell.php" method="post">
<fieldset>
<div class="control-group">
<select name="symbol">
<option value="blank"></option>
<?php foreach ($shares as $symbol):?>
<option value="symbol"><?= $symbol["symbol"]?></option>
<? endforeach ?>
</select>
</div>
<div class="control-group">
<button type="submit" class="btn">Sell all shares</button>
</div>
</fieldset>
</form>
的投資組合從表時,空白頁顯示刪除? – 2013-03-16 18:08:22
由於某種原因,符號未被傳遞給查詢,因此它仍然存在 – tironci 2013-03-16 18:10:55
。如果我刪除了符號,那麼整個投資組合將根據用戶標識被刪除。 – tironci 2013-03-16 18:14:34