I am working with a small parts inventory database (MySQL). I want to add a page where one can narrow down the parts based on their physical location (Parts are in Bins, in Shelves, in Cabinets, in Rooms). I am having a hard time moving from one drop down menu to the next. The first drop down menu returns the correct value, but the other menus never poplulate. here's the code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{ die ('Could not connect: ' . mysql_error());}
mysql_select_db("08",$con);
$result0 = mysql_query("SELECT DISTINCT Room FROM location");
echo "<form method='get' action='$PHP_SELF'>
<select name='rooms'>";
while ($row0 = mysql_fetch_array($result0))
{
echo "<option value=" . $row0['Room'] . ">" . $row0['Room'] . "</option>";
}
echo "<input type='submit' value='Submit'>
</select>
</form>";
$room = $_GET['rooms'];
$result1 = mysql_query("SELECT DISTINCT Cabinet FROM location WHERE Room IS $room");
echo "<form method='get' action='$PHP_SELF'>
<select name='cabinets'>";
while ($row1 = mysql_fetch_array($result1))
{
echo "<option value=" . $row1['Cabinet'] . ">" . $row1['Cabinet'] . "</option>";
}
echo "<input type='submit' value='Submit'>
</select>
</form>";
$cabinet = $_GET['cabinets'];
$result2 = mysql_query("SELECT DISTINCT Shelf FROM location WHERE Room IS $room AND Cabinet IS $cabinet");
echo "<form method='get' action='$PHP_SELF'>
<select name='shelves'>";
while ($row2 = mysql_fetch_array($result2))
{
echo "<option value=" . $row2['Shelf'] . ">" . $row2['Shelf'] . "</option>";
}
echo "<input type='submit' value='Submit'>
</select>
</form>";
$shelf = $_GET['shelves'];
$result3 = mysql_query("SELECT DISTINCT Bin FROM location WHERE Room IS $room AND Cabinet is $cabinet AND Shelf is $shelf");
echo "<form method='get' action='$PHP_SELF'>
<select name='bins'>";
while ($row3 = mysql_fetch_array($result3))
{
echo "<option value=" . $row3['Shelf'] . ">" . $row3['Shelf'] . "</option>";
}
echo "<input type='submit' value='Submit'>
</select>
</form>";
$bin = $_GET['bins'];
mysql_close($con);
?>