0

I'm currently struggling with the sell form of pset7. I want to create a dropbox menu with displays the stocks a users owns and is able to sell. I have a controller called sell.php and a template called sell_form.php. In the controller, I call the query function to get all the stocks a users owns, stored in the variable $symbols. If dumped, the variable looks like this:

Array
(
[0] => Array
    (
        [symbol] => ABC
    )

[1] => Array
    (
        [symbol] => FREE
    )

[2] => Array
    (
        [symbol] => GOOG
    )

)

And my form looks like this:

<form action="sell.php" method="post">
<fieldset>
    <div class="form-group">
    </div>
    <div>
    <?php
        echo "<select name='symbol'>";
        foreach($symbols as $row)
        {
            echo "<option value='".$row["symbol"]."'>".$row["symbol"]."</option>";            
        }
        echo "</select>";
    ?>
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-default">Sell</button>
    </div>
</fieldset>

Back
0

I've been fighting the same problem all day. In my case, I had two issues. First, after getting the list of stocks from the portfolio table, I forgot to pass the array variable in the render statement.

Second, I've been stuck in this mode that, in the controller file, or sell.php, I was doing all of the coding in the else if ($_SERVER["REQUEST_METHOD"] == "POST") section, when in fact, I should have been the stock symbol retrieval query in the else if ($_SERVER["REQUEST_METHOD"] == "GET") section, and before the render statement so that the data is available to the render!

Otherwise, my code looks pretty much the same as yours.

If this answers your question, please click the check mark to accept. Let's keep up on forum housekeeping! ;-)

1
  • Thanks! I indeed did the coding in the POST part while it should be in the GET part! Oct 26 '15 at 8:44
0

The above code works, but make sure you run the query for obtaining the $symbols in the GET part of sell.php, not in the POST part.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .