我不知道爲什麼在第二輪的foreach給我這個錯誤產生的:錯誤的SQL語法,通過一個PHP的foreach
"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 '8,1)' at line 2"
$Ntavolo = Array ([0] => 46 [idordine] => 46) ;
$queryordine= "SELECT `idordine` FROM `ordine` WHERE `tavolo`=$Ntavolo ORDER BY `ordine`.`dataora` DESC LIMIT 1";
$result = mysqli_query($con,$queryordine);
$array=Array ([0] => Array ([id] => 1 [qta] => 1) [1] => Array ([id] => 8 [qta] => 1)) ;
foreach($array as $value){
$row = mysqli_fetch_array($result);
print_r($row);
print_r($array);
$idordine=$row['idordine'];
$queryinsert="INSERT INTO `dettaglio` (`iddettaglio`, `idordine`, `idprodotto`, `quantita`)
VALUES (NULL, ".$idordine.",".$value['id'].",".$value['qta'].");";
mysqli_query($con,$queryinsert)or die(mysqli_error($con));
echo($queryinsert);
};?>
'$ row ['idordine']'也許是空的? – AbraCadaver
或一個字符串.... –
您已經開放SQL注入。由於您使用的是mysqli,請利用[prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)和[bind_param](http://php.net/手動/ EN/mysqli的-stmt.bind-param.php)。而且您不必擔心任何煩人的報價問題。 – aynber