Remove the comma after Cpf
$sql = 'INSERT INTO tabela(nome, nit, rg, cpf,) VALUES ';
--------------------------------------------^
The concatenation here is reversed
$sql=$sql."('"'".$linha_bd['nome']."','".$linha_bd['nit']."','".$linha_bd['rg']."','".$linha_bd['cpf']."')";
wrong:
$sql."('"'".$linha_bd['nome']."'
-----^ |
abriu |
|essa aspa simples ficou da concatenação
To eliminate the php syntax error you can do so:
$sql .= "('{$linha_bd['nome']}'"
Another way to correct syntax error with sprintf, use appropriate parameters for each type of data %s
is for strings.
foreach($arr_entrada as $linha_bd){
$sql .= sprintf("('%s', '%s', '%s', '%s'),", $linha_bd['nome'],$linha_bd['nit'], $linha_bd['rg'], $linha_bd['cpf']);
}
$sql = substr($sql, 0, -1); //remove a ultima virgula se o objetivo é gerar um insert com varios VALUES
phpfiddle - example
Remove the comma in
cpf,
, to concatenate strings use.=
in place of=
which makes a new assignment every turn of the foreach.– rray
My dear, I’m in another trouble now, the mistake has changed this time, (SQLinv¡lido: 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 '( '00000439020154036304', '0006660000', 'MARCOS DE ALMEIDA', '08782952833', ' at line 44)
– user18176