0

I am trying to make a dropdown menu in an html form that relies on information in a databse. This is the code I have:

$rows=query("SELECT Symbol FROM Portfolio WHERE id= ?", $_SESSION["id"]); This part definitely works. AB is angled bracket since this box will not let me type angle brackets.

(AB)form action="sell.php" method="post" (AB) (AB)fieldset(AB) (AB)div class="form-group"(AB) (AB)select name="Stock"(AB)

foreach($rows as $row) { print( '(AB)option value="$row["Symbol"]"(/AB) (AB)/option(AB)'); }

I've also tried the following for the second to last line of code:

echo '(AB)option value="' . $row["Symbol"] . '"(AB)/option(AB);

and numerous other variations on this theme. None of them really seem to work. My dropdown menu has no options; when clicked, it displays a blank space. I'm confused as to why this printing html doesn't seem to work here when it worked previously while making a table with print(""); etc.

1
  • now when I submit the form it tells me that $_POST["Symbol"] is an undefined index (why should it be undefined?). Before, when I had users type in the stock symbol instead of selecting it from a dropdown menu, this wasn't a problem. I did make sure that the select tag in the form had attribute name="Symbol"
    – user1298
    Jun 26, 2014 at 20:56

1 Answer 1

2

It looks like you aren't actually putting anything into the HTML to display the value itself. Can you try something like this?

echo "<option value = \"".$row["Symbol"]."\">".$row["Symbol"]. "</option>";
2
  • Wow, I guess the whole time it was working, just not displaying the name of the stock. Thanks a lot for clearing that up.
    – user1298
    Jun 26, 2014 at 14:47
  • Except now when I submit the form it tells me that $_POST["Symbol"] is an undefined index. Before, when I had users type in the stock symbol instead of selecting it from a dropdown menu, this wasn't a problem. I did make sure that the select tag in the form had attribute name="Symbol"
    – user1298
    Jun 26, 2014 at 14:51

You must log in to answer this question.

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