2

I have 2 pages sell.php and sell_form.php . When a user selects a stock symbol from the drop-down menu in sell_form.php i have a query in sell.php that is supposed to delete that stock symbol from the database, but what i am getting right now is just a blank page when i click on Sell button. I am not sure i fully understand how the value from the drop-down menu is passed to the sell.php form. This is the code i have so far

this is my sell.php file

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"] );
}

this is my 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>
2
  • is the portfolio is deleted from table when the blank page is showing? Commented Mar 16, 2013 at 18:08
  • for some reason symbol is not being passed to the query. if i remove symbol then the whole portfolio gets deleted according to the user id. Commented Mar 16, 2013 at 18:14

1 Answer 1

5

We think in sell_form.php,

<option value="symbol"><?= $symbol["symbol"]?></option>

should be changed as

<option value="<?= $symbol["symbol"]?>"><?= $symbol["symbol"]?></option>

Other-wise in sell.php

the delete statement is interpreting as -

DELETE FROM shares WHERE id = <<Spefied User Id>> AND symbol = 'symbol';

Thnaks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.