我是新來的,在stackoverflow上。在while循環上執行select查詢後,並非所有行都被插入到表中 - PHP/MYSQL
我正在執行一個選擇查詢來填充我需要的輸出。當它從查詢中提取行時,每個已經被提取的行都是我將它們插入到一個特定的表中。但是,我需要實現的確切數量的行是1,767行,但執行查詢後,1759是輸出。我有8行丟失。
我的代碼有什麼問題?
這裏是我的代碼:
$query2 = "SELECT trihadjustmentitems.AdjID AS `adjid1`, trihadjustment.Adj_ID AS `adjid2`,
trihadjustment.AdjToUnitID AS `adjtounitid`, trihadjustment.AdjDate AS `adjdate`, trihadjustmentitems.InvItemsID AS `invitemid`,
trihadjustmentitems.SlsItemsID AS `slsitemid`, trihadjustmentitems.RecipeID AS `recipeid`, trihadjustmentitems.Remark AS `remark`,
trihadjustmentitems.AdjQty AS `adjqty`,
trihadjustment.StockCenter_ID AS `stockcenterid1`, trihadjustmentitems.StockCenter_ID AS `stockcenterid2`
FROM trihadjustmentitems
INNER JOIN trihadjustment ON trihadjustmentitems.AdjID = trihadjustment.Adj_ID";
$result2 = mysqli_query($connection, $query2);
while($row2 = mysqli_fetch_array($result2))
{
$query3 = "INSERT INTO adjustments (adjid1, adjid2, adjtounitid, adjdate, invitemid, slsitemid, recipeid, remark, adjqty, stockcenterid1, stockcenterid2) VALUES ('$row2[adjid1]', '$row2[adjid2]', '$row2[adjtounitid]', '$row2[adjdate]', '$row2[invitemid]', '$row2[slsitemid]', '$row2[recipeid]', '$row2[remark]', '$row2[adjqty]', '$row2[stockcenterid1]', '$row2[stockcenterid2]')";
$result3 = mysqli_query($connection, $query3);
}
可能是因爲您沒有使用參數化查詢或轉義值(mysqli_real_escape_string)這些值而導致8行中包含單個qoute(')的SQL查詢('),這也有助於防止SQL注入攻擊。 –