I am trying to build a reusable page using PHP only at this point. Unless someone shows me what I'm missing, I'll be forced to do this with multiple pages, or use java as a workaround.
My database has separate tables of Names, Model, and Items. The SQL statement has been the easy part of this so far. Where I am having my problem is building the dropdown boxes such that each one updates the next box. For instance.
The first box contains a list of MFG Names. The next two boxes will be empty until selected. Once the Name has been selected, I want to set that option as SELECTED and populate the second box with all of the available Models of that particular MFG. Once this is selected, the Query will be updated to populate a table with all of the available items.
Here is where I am so far and it just doesn't work. The first box gets populated, but when I select the second box, the page reloads just as if nothing had been selected at all.
Help me see the light!
<html>
<head>
<title> Title Information </title>
</head>
<body>
<?php
print "Name $MFGName";
if (!isset($MFGName)): // If the manufacture has not been selected
?>
<form action="<?=$PHP_SELF?>" method="post">
<div align="left"><left><p>Search Mfg.
<select name="MFGName">
<?php
$hostname = "localhost";
$user = "user";
$password = "mypass";
$database = "MyData";
$connection = @mysql_connect($hostname, $user, $password);
@mysql_select_db($database,$connection);
$query = "SELECT MFGName FROM tblMFG ORDER BY MFGName";
$result = @($query, $connection);
if(mysql_num_rows($result)) {
// we have at least one item, so show all items as options in select form
while($row = mysql_fetch_row($result)) {
print("<option value=\"$row[0]\">$row[0]</option>");
}
} else {
print("<option value=\"\">No records were found, sorry.</option>");
}
?>
</select><input type="submit" name="MFGName"></p></left></div>
</form>
<form action="<?=$PHP_SELF?>" method="post">
<div align="left"><left><p>Search Model
<select name="RMN">
<?php
elseif (!isset($ModelNo)): // If the model has not been selected
$query ="SELECT ModelNo FROM tblRMN ORDER BY ModelNo";
$result = @($query, $connection);
if(@mysql_num_rows($result)) {
// we have at least one item, so show all items as options in select form
while($row = @mysql_fetch_row($result)) {
print("<option value=\"$row[0]\">$row[0]</option>");
}
} else {
print("<option value=\"\">No records were found, sorry</option>");
}
?>
</select><input type="submit" name="RMN"></p></left></div>
</form>
<?php
else:
endif;
?>
</body>
</html>