0

只是一个快速的问题。我相信它没有我想的那么复杂。我有一个有 4 个下拉菜单的页面。这些都是从 MySQL 数据库中填充的。提交后,我希望将这些选项插入到不同的表中。对于我的生活,我无法弄清楚这一点。请让我知道一些可以实现这一目标的代码,我们将不胜感激。我已经尝试了一天左右。在此先感谢您的帮助。另请注意,这些只是代码片段。有些可能没有结束标签等。

PHP代码:

    <?php

//connecting to DB
$myServer   = "";
$myUsername = "";
$myPassword = "";
$myDatabase = "";

$myQuery1   = "SELECT DispatchUrgency.DispatchUrgencyID, DispatchUrgency.DispatchUrgencyName FROM DispatchUrgency ORDER BY DispatchUrgency.DispatchUrgencyName";
$myQuery2   = "SELECT DispatchStatus.DispatchStatusID, DispatchStatus.DispatchStatusName FROM DispatchStatus ORDER BY DispatchStatus.DispatchStatusID";
$myQuery3   = "SELECT Installer.InstallerID, CONCAT_WS(' ', PackingSlipLocation.ContactName, Installer.InstallerRegion, PackingSlipLocation.ContactPhone) as expr1 FROM PackingSlipLocation INNER JOIN Installer ON PackingSlipLocation.PackingSlipLocationID=Installer.InstallerPackingSlipLocationID";
$myQuery4   = "SELECT Location.LocationID, CONCAT_WS(' ', SystemName, id1poc, sitenamelocation, siteaddress1) as expr2 FROM Location";
$myQuery5   = "SELECT DispatchUrgency.DispatchUrgencyID FROM DispatchUrgency WHERE DispatchUrgencyName = '".$_POST['element_11']."'";

$myConnection = mysql_connect($myServer,$myUsername,$myPassword);
if (!$myConnection){
   die('Conncetion Failed:' . mysql_error()  );
}
@mysql_select_db($myDatabase) or die("Unable to select database");


$result1 = mysql_query($myQuery1) or die (mysql_error());
$result2 = mysql_query($myQuery2) or die (mysql_error());
$result3 = mysql_query($myQuery3) or die (mysql_error());
$result4 = mysql_query($myQuery4) or die (mysql_error());
$options = "";

if(mysql_num_rows($result1)){ 
$select1= '<select name="element_11" class="element select large" id="element_11">';   
while($rs=mysql_fetch_array($result1)){ 
      $select1.='<option value="'.$rs['DispatchUrgencyID'].'">'.$rs['DispatchUrgencyName'].'</option>'; 
  } 
} 
$select1.='</select>'; 


if(mysql_num_rows($result2)){ 
$select2= '<select class="element select large" id="element_12" name="element_12">';   
while($rs=mysql_fetch_array($result2)){ 
      $select2.='<option value="'.$rs['DispatchStatusID'].'">'.$rs['DispatchStatusName'].'</option>'; 
  } 
} 
$select2.='</select>';


if(mysql_num_rows($result3)){ 
$select3= '<select class="element select large" id="element_13" name="element_13">';   
while($rs=mysql_fetch_array($result3)){ 
      $select3.='<option value="'.$rs['Installer.InstallerID'].'">'.$rs['expr1'].'</option>'; 
  } 
} 
$select3.='</select>';


if(mysql_num_rows($result4)){ 
$select4= '<select class="element select large" id="element_14" name="element_14">';   
while($rs=mysql_fetch_array($result4)){ 
      $select4.='<option value="'.$rs['Installer.InstallerID'].'">'.$rs['expr2'].'</option>'; 
  } 
} 
$select4.='</select>';

?>

HTML表格:

<form id="form_631187" class="appnitro"  method="post" action="">
        <div class="form_description">
            <h2>Dispatch Form</h2>
        </div>                      


    <ul>

        <li id="li_1" >
        <label class="description" for="element_1">Dispatch ID </label>
        <div>
            <input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_11" >
        <label class="description" for="element_11">Urgency</label>
        <div>


        <?php echo $select1; ?>

        </div> 
        </li>       
        <li id="li_12" >

        <label class="description" for="element_12">Status</label>

        <div>

        <?php echo $select2; ?>

        </div> 

        </li>       
        <li id="li_13" >

        <label class="description" for="element_13">Installers</label>

        <div>   

        <?php echo $select3; ?>

        </div> 

        </li>   
        <li id="li_14" >

        <label class="description" for="element_14">Location </label>

        <div>

        <?php echo $select4; ?>

        </div> 

        </li>   
4

1 回答 1

0

我注意到的两件事:

<form id="form_631187" class="appnitro"  method="post" action="">

没有动作参数。您需要输入以下内容:

<form id="form_631187" class="appnitro"  method="post" action="form_handler.php">

然后您需要创建 form_handler.php 并在 $_POST 数组中获取表单内容。在您创建的此页面上,您需要对包含表单中的值的表进行更新/插入。

于 2013-05-21T23:31:16.270 回答