Source code of dbAdd1.php
<html>
<head>
<title>Adding information in a database</title>
</head>
<body>
<h2>Add an item</h2>
<form action='dbAdd2.php' method='get'>
<?php
// Rather than listing my MySQL password directly in this PHP
// page, I've stored it in an external file
$allLines = file("mysql.txt");
$password = trim($allLines[0]);
$dbLink = mysql_connect("localhost", "tboegel", $password);
mysql_select_db("clearwater", $dbLink);
$itemQuery = "SELECT item_id, item_desc FROM item "
. "ORDER BY item_desc ";
$itemRecordset = mysql_query($itemQuery, $dbLink);
$colorQuery = "SELECT color FROM color "
. "ORDER BY color ";
$colorRecordset = mysql_query($colorQuery, $dbLink);
print "<table border=1>";
print "<tr><td>Item:</td>";
print "<td><select name='item_id' size=1>";
print "<option selected value='0'>Pick an item...";
while ($itemRow = mysql_fetch_assoc($itemRecordset)) {
print "<option value='" . $itemRow['item_id'] . "'>"
. $itemRow['item_desc'];
}
print "</select>";
print "</td></tr>";
print "<tr><td>Color:</td>";
print "<td><select name='color' size=1>";
while ($colorRow = mysql_fetch_assoc($colorRecordset)) {
print "<option value='" . $colorRow['color'] . "'>"
. $colorRow['color'];
}
print "</select>";
print "</td></tr>";
print "<tr><td>Size:</td>";
print "<td><input type='text' name='inv_size'></td></tr>";
print "<tr><td>Price:</td>";
print "<td><input type='text' name='inv_price'></td></tr>";
print "</table>";
mysql_free_result($itemRecordset);
mysql_free_result($colorRecordset);
mysql_close($dbLink);
?>
<input type='submit' value='Add Item'>
</form>
</body>
</html>