如何获取下拉数据我们从其他表中获取编辑数据的位置

时间:2016-03-28 08:24:58

标签: php mysql

我希望在添加新记录表单中同样下载Hardware_ID WHERE我从另一个表中获取更新表单的数据。

这是我的更新(编辑)表单的示例。 Update Form

这是我的添加新记录表格。 Adding new record Form

这是我的更新表单代码。我使用相同的代码,如我添加新记录但我收到错误(错误在更新表单中)。

<?php

//get the data
$Asset_ID = $_GET['Asset_ID'];
$Hardware_ID = $_GET['Hardware_ID'];
$Vendor_ID = $_GET['Vendor_ID'];
$PO_ID = $_GET['PO_ID'];


?>

<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0'   cellpadding='10'    
 bgcolor = "White">
 <tr>
   <th colspan = '2'>ASSET UPDATE FORM</th>
 </tr>

 <tr>
     <td align='center'>Asset ID :</td>
     <td><input type = "varchar" name = "Asset_ID" value = "<?php echo 
          $Asset_ID; ?>" readonly></td>
</tr>

<tr>
   <td align='center'> Hardware ID: </td>
   <td><input type = "varchar" name = "Hardware_ID" value = "<?php echo 
    $Hardware_ID?>">

    <?php
    $query = "SELECT * FROM hardware2 ORDER BY Hardware_ID";
    $result = mysql_query($query);

    if(mysql_num_rows($result)) 
    {
        while ($id = mysql_fetch_row($result))

            {
                echo "<option value='" . $id[0] . "'>" . $id[0] . " : " . 
                $id[1] . " </option>";
            }

    }
?>
    </select> 


</tr>



 <tr>
    <td align='center'>Vendor ID :</td>
    <td><input type = "varchar" name = "Vendor_ID" value = "<?php echo 
     $Vendor_ID; ?>"></td>
</tr>

<tr>
  <td align='center'>PO ID :</td>
   <td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?
   >"></td>
   </td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
 </tr>
<a href = "View_Asset2.php">Back to Asset</a>
</table>
</form>

感谢您的帮助,问候

2 个答案:

答案 0 :(得分:0)

选择框语法错误

<?php
//get the data
$Asset_ID    = isset($_GET['Asset_ID']) ? $_GET['Asset_ID'] : 0;
$Hardware_ID = isset($_GET['Hardware_ID']) ? $_GET['Hardware_ID'] : 0;
$Vendor_ID   = isset($_GET['Vendor_ID']) ? $_GET['Vendor_ID'] : 0;
$PO_ID       = isset($_GET['PO_ID']) ? $_GET['PO_ID'] : 0;
?>

<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0'   cellpadding='10' bgcolor = "White">
 <tr>
   <th colspan = '2'>ASSET UPDATE FORM</th>
 </tr>

 <tr>
     <td align='center'>Asset ID :</td>
     <td><input type = "varchar" name = "Asset_ID" value = "<?php echo $Asset_ID; ?>" readonly></td>
</tr>

<tr>
   <td align='center'> Hardware ID: </td>
   <td><input type = "varchar" name = "Hardware_ID" value = "<?php echo $Hardware_ID?>">

    <select id="Your_id" name="Your_name">
    <?php
    $query = "SELECT * FROM hardware2 ORDER BY Hardware_ID";
    $result = mysql_query($query);

    if(mysql_num_rows($result)) 
    {
        while ($id = mysql_fetch_row($result))
        {
            echo "<option value='".$id[0]."'>".$id[0]." : ".$id[1]."</option>";
        }
    }
    ?>
    </select> 
</tr>

 <tr>
    <td align='center'>Vendor ID :</td>
    <td><input type = "varchar" name = "Vendor_ID" value = "<?php echo $Vendor_ID; ?>" /></td>
</tr>

<tr>
  <td align='center'>PO ID :</td>
   <td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?>" /></td>
   </td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
 </tr>
<a href = "View_Asset2.php">Back to Asset</a>
</table>
</form>

答案 1 :(得分:0)

可能不需要此表单中的选择框

<?php
//get the data
$Asset_ID    = isset($_GET['Asset_ID']) ? $_GET['Asset_ID'] : 0;
$Hardware_ID = isset($_GET['Hardware_ID']) ? $_GET['Hardware_ID'] : 0;
$Vendor_ID   = isset($_GET['Vendor_ID']) ? $_GET['Vendor_ID'] : 0;
$PO_ID       = isset($_GET['PO_ID']) ? $_GET['PO_ID'] : 0;
?>

<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0'   cellpadding='10' bgcolor = "White">
 <tr>
   <th colspan = '2'>ASSET UPDATE FORM</th>
 </tr>

 <tr>
     <td align='center'>Asset ID :</td>
     <td><input type = "varchar" name = "Asset_ID" value = "<?php echo $Asset_ID; ?>" readonly></td>
</tr>

<tr>
   <td align='center'> Hardware ID: </td>
   <td><input type = "varchar" name = "Hardware_ID" value = "<?php echo $Hardware_ID?>">
</tr>

 <tr>
    <td align='center'>Vendor ID :</td>
    <td><input type = "varchar" name = "Vendor_ID" value = "<?php echo $Vendor_ID; ?>" /></td>
</tr>

<tr>
  <td align='center'>PO ID :</td>
   <td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?>" /></td>
   </td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
 </tr>
<a href = "View_Asset2.php">Back to Asset</a>
</table>
</form>