<?php
if($action=='sefaresh'){
$cookiname=$_COOKIE['mybasket'];
$stmt = $db->prepare("SELECT `idsabad`,`cookiname`,`idmahsool`,`tedad`,`pardakht` FROM `sabad` WHERE `cookiname`=?");
$stmt->bind_param("s", $cookiname);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($idsabad11, $cookiname1, $idmahsool1, $tedad1, $pardakht1);
while ($stmt->fetch()) {
$id = $idsabad11;
$stmt = $db->prepare("UPDATE `sabad` SET `tedad`=? WHERE `idsabad`=?");
$stmt->bind_param("ii", $_POST['tedad'.$idmahsool1], $id );
$stmt->execute();
}
}
?>
答案 0 :(得分:1)
问题是由于语句对象$stmt
。您正在覆盖$stmt
循环中的外部语句对象while()
以执行UPDATE
操作,即$db->prepare("UPDATE
内SET ...
sabad while()
将返回一个不同的语句对象,您将其分配给$stmt
,从而覆盖原始/外部$stmt
。这就是为什么一行得到更新的原因。
因此,请按以下方式更改while()
循环,
while ($stmt->fetch()) {
$id = $idsabad11;
$stmt1 = $db->prepare("UPDATE `sabad` SET `tedad`=? WHERE `idsabad`=?");
$stmt1->bind_param("ii", $_POST['tedad'.$idmahsool1], $id );
$stmt1->execute();
$stmt1->close();
}