Drop down lists SELECT elements) are fairly common in HTML forms. They allow the user to select from a list rather than typing in the data. They are also common in databases because they make it easier for the user and also restrict the user to valid data.
To create a drop down form in HTML you list the possible choices as OPTIONS in a SELECT element. PHP can create this list from MySQL data. The confusion comes as usual with all the escaping of quotes but otherwise it is a fairly simple loop embedded in an HTML form. This shows one way to slightly reduce the complexity of the PHP because the form starts and end outside of the PHP saving a couple of echo lines:
<body>
<form method="post" action="somepage.php">
<select id="cdTitle" name="cdTitle">
<?php
$mysqlserver="localhost";
$mysqlusername="test";
$mysqlpassword="test";
$link=mysql_connect(localhost, $mysqlusername, $mysqlpassword) or die ("Error connecting to mysql server: ".mysql_error());
$dbname = 'test';
mysql_select_db($dbname, $link) or die ("Error selecting specified database on mysql server: ".mysql_error());
$cdquery="SELECT cdTitle FROM firsttable";
$cdresult=mysql_query($cdquery) or die ("Query to get data from firsttable failed: ".mysql_error());
while ($cdrow=mysql_fetch_array($cdresult)) {
$cdTitle=$cdrow[cdTitle];
echo "<option>
$cdTitle
</option>";
}
?>
</select>
</form>
</body>
Paste this into a new PHP page, save as mysqldropdown.php and upload. It should be fairly clear how it works but look again at that page which explained some of the fields which can be used in an HTML form if you need to.
As an alternative you could show the user the CD title and artist but send the cdReference to provide another way to use the mysqlupdate2.php page:
while ($cdrow=mysql_fetch_array($cdresult)) {
$cdTitle=$cdrow[cdTitle];
echo "<option value=\"$cdReference\">
$cdTitle cdArtist
</option>";
}
Change the SELECT query to include the cdArtist field. You would also need to change the form's ACTION and METHOD to mysqlupdate2.php and get and add a submit button.




