I am trying to have a drop down box that is populated through mySQL and PhP, populate two read only boxes, with PartName and Cost. The drop down box get's populated with the correct choices, and then when I choose a choice from that. My Parts table has these 3 columns: PartID, PartName, Cost. it doesn't populate the read only boxes Here's what the code looks like:
if (!empty($_POST)) {
$partid = $_GET["PartID"];
$sql = "SELECT * FROM Parts WHERE PartID = '$partid'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$part_name = $row ["PartName"];
$part_cost = $row ["Cost"];
}
$sql = "SELECT PartID FROM Parts WHERE PartID LIKE 'C0%'";
$result = mysql_query($sql);
echo "<select name='PartID' onchange='document.getElementById(\'form1\').submit();'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['PartID'] . "'>" . $row['PartID'] . "</option>";
}
echo "</select>";
echo "<input type='text' value='".$part_name."' />";
echo "<input开发者_如何学Go type='text' value='".$part_cost."' />";
Assuming that form1 contains the select box, when the page is submitted, you ar checking if $_POST is not empty, but then taking values from $_GET. If your form posts, then both the check and assignment need to come from the $_POST array, otherwise, both need to come from the $_GET array.
精彩评论