只是一个简单的问题。我相信它并不像我想的那么复杂。我有一个页面,有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>
答案 0 :(得分: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数组中的表单内容。在您创建的此页面上,您需要对包含表单中值的表进行更新/插入。