douxian8883 2011-03-04 18:16
浏览 29

我试图有一个通过mySQL和PhP填充的下拉框,填充两个只读框,具有PartName和Cost

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 type='text' value='".$part_cost."' />";
  • 写回答

1条回答 默认 最新

  • dongmi8980 2011-03-04 19:06
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教