I'm trying to get my PHP to display all the product names in a dropdown menu. However it only displays the first row twice.
$prodNameSQL="select prodName from product";
//execute SQL query or return an error
$exeProdNameSQL=mysql_query($prodNameSQL) or die(mysql_error());
//create array of records & populate it with result of the execution of the SQL query
$array=mysql_fetch_array($exeProdNameSQL);
echo "<select name='productCombo'>";
foreach($array as $value) {
echo "<option value=".$value.">".$value;
echo "</option>";
}
echo "</select>";
I know that I should be using mysqli and mysql is depreciated but its beyond my control.
Thanks.
mysql_database extension in new code a Kitten is strangled somewhere in the world it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning thePDOormysqlidatabase extensions and prepared statements. Start here