0
我用這個代碼的工作:更新陣列PDO
$sortId = $_POST['sortId'];
$sortName = $_POST['sortName'];
$sortType = $_POST['sortType'];
$location = $_POST['location'];
$active = $_POST['active'];
$sql = "UPDATE `sorts` SET `sort` = :sort
WHERE `sort_id` = :sort_id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':sort', $sort);
$stmt->bindParam(':sort_id', $sort_id);
$db->beginTransaction();
foreach($sortName as $i => $sort)
{
$sort_id = $sortId[$i];
$stmt->execute();
}
$db->commit();
它的工作原理,它應該讓我繼續添加
<div class="chuteAudit">
<div>
<input type="hidden" name="sortId[]" value="<?php echo $name['sort_id']; ?>" >
<input type="text" name="sortName[]" value="<?php echo $name['sort']; ?>" >
<select name="sortType[]" >
<optgroup label="<?php echo $name['shipping_sort'] ?>">
<option value="amzl[]">AMZL</option>
<option value="other[]">Other</option>
</optgroup>
</select>
<select name="location[]" >
<option value=""><?php echo $name['section'] ?></option>
<option value="chutes">Chutes</option>
<option value="spine">Spine</option>
<option value="RMspine">Royal Mail spine</option>
<option value="RMchutes">Royal Mail chutes</option>
<option value="exceptions">Exceptions</option>
<option value="teamLift">Team lift</option>
</select>
<select name="active[]" >
<option value=""><?php echo $name['active'] ?></option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
</div>
我曾以爲額外的價值
$sortId = $_POST['sortId'];
$sortName = $_POST['sortName'];
$sortType = $_POST['sortType'];
$location = $_POST['location'];
$active = $_POST['active'];
$sql = "UPDATE `sorts` SET `sort` = :sort, `shipping_sort` = :sortType
WHERE `sort_id` = :sort_id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':sort', $sort);
$stmt->bindParam(':sort_id', $sort_id);
$stmt->bindParam(':sortType', $sortType);
$db->beginTransaction();
foreach($sortName as $i => $sort)
{
$sort_id = $sortId[$i];
$stmt->execute();
}
$db->commit();
HTML這會很好,因爲它只是增加了一些已經可以工作的東西,但它並不像我原先想象的那麼簡單是,目前我收到了錯誤信息Notice: Array to string conversion
我知道它與我添加的附加代碼有關,但我不確定自己做錯了什麼。
當然啊,謝謝,我會接受答案,當它讓我。 –