I'm rather new to PHP (just picked it up for a course on CS) and I'm right now trying to display some values from a Database, namely stocks. Right now I'm running into some issue though as I'm trying to display the stocks symbol from the database in a nice option menu. But when I try to retrieve the value via $_POST["stock"] ("stock" is the name of the option) it displays me an error of "Undefinex index: stock".
Now if I choose the above option (the option before the php code) it actually works perfectly and "stock" is retrievable (and displays nothing, as anticipated).
Now my question is: What did I do wrong and how can I make the name "stock" show the value of $_POST["stock"]
<select class="form-group">
<option class='form-control' type='text' name='stock'></option>
<?php
$rows = query("SELECT * FROM stocks WHERE id = ?", $_SESSION["id"]);
foreach ($rows as $row)
{
print("<option class='form-control' name='stock'>{$row["symbol"]}</option>");
}
?>
</select>