我构建了一个将Service Mechanic客户存储到数据库的站点。它具有更新条目的功能。我有一个下拉选择字段工作正常(它仍然如此)。但是我在事后添加的第二个只返回空白信息。
这是我的代码。
include('connect.php');
$table='currentJobs';
$tableMap=array('Date','Name','Phone','Bike_Year','Bike_Model','Current_Status','SType','Mechanic','Revenue','Notes');
$sqlArray=array();
foreach ($tableMap AS $key){
$sqlArray[]="`".$key."`='".mysql_real_escape_string(@$_POST[$key],$dbLink)."'";
}
$sql="UPDATE `".$table."` SET ".join(',',$sqlArray)." WHERE `id`='".$_POST['id']."'";
if (mysql_query($sql,$dbLink)){
echo 'Data for <i>' .$_POST['Name'].'</i> was successfully updated <br />'.$sql.'.';
}
else {
echo 'Sorry, could not process the following sql: <br /><code>'.$sql.'</code>';
echo mysql_errno($dbLink) . ": " . mysql_error($dbLink). "\n";
}
mysql_close($dbLink);
它正在归还:
Data for Test User was successfully updated
UPDATE `currentJobs` SET `Date`='04/14/2013',`Name`='Test User',`Phone`='1234567890',`Bike_Year`='2001',`Bike_Model`='FXD',`Current_Status`='Checked In',`SType`='',`Mechanic`='All',`Revenue`='0',`Notes`='' WHERE `id`='55'.
我的表格如下:
<form action="updated.php" method="POST" name="dataForm" id="dataForm">
<fieldset>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>"/>
<label>Arrival<input type="text" name="Date" value="<?php echo $row['Date']; ?>"/></label><br />
<label>Name<input type="text" name="Name" value="<?php echo $row['Name']; ?>"/></label><br />
<label>Phone Number<input type="text" name="Phone" value="<?php echo $row['Phone']; ?>"/></label><br />
<label>Bike Year<input type="text" name="Bike_Year" value="<?php echo $row['Bike_Year']; ?>"/></label><br />
<label>Bike Model<input type="text" name="Bike_Model" value="<?php echo $row['Bike_Model']; ?>"/></label><br />
<label>Current Status<!--Update Status types on two pages-->
<select name="Current_Status" form="dataForm" value="<?php echo $row['Current_Status']; ?>">
<option value="Checked In">Checked In</option>
<option value="Inline For Service">Inline For Service</option>
<option value="In Service">In Service</option>
<option value="On Hold - Parts on Order">On Hold - Parts on Order</option>
<option value="On Hold - Parts to Paint">On Hold - Parts to Paint</option>
<option value="On Hold - Waiting To Hear From Customer">On Hold - Waiting To Hear From Customer</option>
<option value="Test Ride">Test Ride</option>
<option value="Completed - Awaiting Pick Up">Completed - Awaiting Pick Up</option>
<option value="Picked Up">Picked Up</option>
</select>
</label><br />
<!--update Service Type in two pages.-->
<label>Service Type</label>
<select name="SType" form="" value="<?php echo $row['SType']; ?>">
<option value="Spec Service Interval">Spec Service Interval</option>
<option value="Interim Service">Interim Service</option>
<option value="Diagnostics">Diagnostics</option>
<option value="Tires">Tires</option>
<option value="Engine– Light Work (1-3 hrs)">Engine– Light Work (1-3 hrs)</option>
<option value="Engine– Medium Work (3-8 hrs)">Engine– Medium Work (3-8 hrs)</option>
<option value="Engine– Heavy Work (8-24 hrs)">Engine– Heavy Work (8-24 hrs)</option>
<option value="Drivetrain– Light">Drivetrain– Light</option>
<option value="Drivetrain - Heavy">Drivetrain - Heavy</option>
<option value="Dyno Tune">Dyno Tune</option>
</select>
<br />
<label>Mechanic Assigned<input type="text" name="Mechanic" value="<?php echo $row['Mechanic']; ?>"/></label><br />
<label>Final Revenue<input type="text" name="Revenue" value="<?php echo $row['Revenue']; ?>"/></label><br />
<label>Notes<input type="text" name="Notes" value="<?php echo $row['Notes']; ?>"/></label><br />
<input type="submit" value="Update" style="color:#000000;" />
</fieldset>
为什么第二个选择不发送数据?
答案 0 :(得分:0)
select
标记没有名为value
的属性。
http://www.w3schools.com/tags/tag_select.asp
更新
这样的事情会更有用:
<label>Service Type</label>
<select name="SType" form="dataForm">
<?php
$Stypes = array(
"Spec Service Interval",
"Interim Service",
"Diagnostics",
"Tires",
"Engine– Light Work (1-3 hrs)",
"Engine– Medium Work (3-8 hrs)",
"Engine– Heavy Work (8-24 hrs)",
"Drivetrain– Light",
"Drivetrain - Heavy",
"Dyno Tune",
);
foreach($Stypes as $value){
if ($value==$row['SType']){
echo "<option value=\"$value\" selected=\"selected\">value</option>";
} else {
echo "<option value=\"$value\">$value</option>";
}
}
?>
</select>
假设你从数据库中撤回$row['Stype']
。
同样正如@Fred所说,如果您使用的是HTML5,则可能需要为form
属性指定表单ID (尽管这在IE中不起作用...然而)。
你也可以在你正在进行插入的页面上进行print_r($_POST)
调试,只是为了验证发生了什么。