用dreamweaver改寫php迴圈以達到一次更新多個資料,結果依書上的說明,直接將伺服器行為的更新記錄稍作改
主要加上:
$countNum=count($_POST['index']);
for($i=0 ; $i<$countNum ; $i++){
$updateSQL = sprintf("UPDATE ``211`` SET sn=%s, `number`=%s, name_student=%s WHERE `index`=%s",
GetSQLValueString($_POST['test'][$i], "int"),
GetSQLValueString($_POST['test3'][$i], "int"),
GetSQLValueString($_POST['test2'][$i], "text"),
GetSQLValueString($_POST['Index'][$i], "int"));mysql_select_db($database_load, $load);
$Result1 = mysql_query($updateSQL, $load) or die(mysql_error());
}
結果依書上的邏輯更改後,在更新時卻會出現
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '211`` SET sn=980801, `number`=1, name_student='方發' WHERE `index`=1' at line 1
後來發現問題在如下圖所指的,多了兩個單引號
將其刪除後,就可以了!