1
我有一個表單更新單個表格行中的多個字段。其中一個字段需要是選擇/選項框,第一個選項是現有條目。從現有表條目的第一個選項中選擇選項
我已經試過這樣: -
while ($row=mysql_fetch_object($sql)) {
$repairRqd = "'.$row->repair_required.'";
//print out table contents and add id into an array and email into an array
echo '<tr>
<td class="hidden"><input name="id3[]" value='.$row->id.' type="hidden" readonly> </td>
<td align="center">'.$row->id.'</td>
<td align="center">'.$row->repaired_by.'</td>
<td align="center">'.date("l",strtotime($row->received_date)).'</br>'.$row->received_date.'</td>
<td align="center"><input name="customer_name[]" value="'.$row->customer_name.'" maxlength = "50" size = "10"</td>
<td align="center"><input name="repair_required[]" value="'.$row->repair_required.'" maxlength="249" size="40"></td>
<td align="centre"><select name="status">
<option value="'.$row->status.'">'.$row->status.'</option>
<option value="Received">Received</option>
<option value="In Progress">In Progress</option>
<option value="On Hold">On Hold</option>
<option value="Written Off">Written Off</option>
<option value="Cancelled">Cancelled</option>
<option value="Complete">Complete</option>
<option value="Dispatched">Dispatched</option>
<option value="Collected">Collected</option>
</select></td>
</tr>';
隨着PHP: -
//get data from form
$id3 = $_POST['id3'];
$repairRequired = $_POST['repair_required'];
$status1 = $_POST['status'];
$customerName = $_POST['customer_name'];
// set queries for each item in the row
foreach ($id3 as $key => $value){
$query = "UPDATE repair SET repair_required = '$repairRequired[$key]' WHERE id = $value";
$query2 = "UPDATE repair SET status = '$status1[$key]' WHERE id = $value";
$query7 = "UPDATE repair SET customer_name = '$customerName[$key]' WHERE id = $value";
//execute query
mysql_query($query);
mysql_query($query2);
mysql_query($query7);
}
奇怪的是,我得到的現有內容的選項列表中顯示出來,但是如果我改變它(通過選擇另一個選項)寫入數據庫的所有內容都是所選選項的第一個字母。
我在POST ['status']和變量$ status1上都做了一個var_dump,並且它們都顯示了我所期望的選擇的完整文本。
我不明白爲什麼完整的字符串沒有被寫入數據庫,並會非常感謝任何幫助嗎?
謝謝。我無法看到它爲我的生活,但它現在很明顯:) – Jason
我試圖但由於某種原因無法達到五分鐘。一旦我被系統允許,將盡快這樣做。 - 現在完成:) – Jason