1
我正在爲我的學校開展項目,我激活了用戶帳戶工作,如果管理員想一次激活一個用戶,但是每當管理員想要更新多個在一次記錄,它不會工作 我想包括foreach循環內更新SQL,但它給了我一個錯誤:無效的foreach參數() 懇求你們幫助我,同時激活多個用戶
if(isset($_POST['activate'])){
$impid = implode(',', $_POST['SSU']);
// for each .. to update more than one at once.
foreach($impid AS $i){
$sql = "UPDATE Accounts SET Activated = '".$_POST['activate']."' WHERE SSU IN('" . $i . "') ";
$result = mysqli_query($dbCIE, $sql) or die(mysqli_error($dbCIE));
}
// to test. if anything got effected..
if (mysqli_affected_rows($dbCIE) > 0) {
echo "<script type='text/javascript'> alert('Successfully Updated ')</script>";
}
else {
echo "<script type='text/javascript'> alert('Failed to Update ')</script>";
} // end the test.
}else{echo "<script type='text/javascript'> alert(' Select Whether to Activare Or Deactive ')</script>";}
}
} // end of first if $_post[update]
'implode'返回一個字符串,所以你不能(並且確實不需要)將它傳遞給foreach。 – andrewsi
謝謝您,先生,我只是修復它 – ayay
您的$我看起來像 –