SQL syntax error

1

I come again with a similar error in the syntax of my SQL. I've tried a few times and so far nothing. If you can give me some help, thank you. Here is my code:

$sql="INSERT INTO processos   
    (
        processo, 
        numero_beneficio, 
        autor, 
        cpf, 
        nit, 
        data_nascimento, 
        nome_mae, 
        nome_aps, 
        codigo_aps, 
        uf_aps, 
        nome_gex, 
        codigo_gex, 
        data_intimacao, 
        data_distribuicao, 
        data_audiencia, 
        processo_prazo,
        processo_destino,
        assunto,
        cod_assunto,
        localizacao
    )
    VALUES";

foreach($dados as $linha_bd)
{                               

$sql=$sql."(
'".$linha_bd['processo']."',
'0006660000',
'".$linha_bd['autor']."',
'".$linha_bd['cpf']."',
'".$linha_bd['nit']."',
'".$linha_bd['data_nascimento']."',
'".$linha_bd['nome_mae']."',
'".$linha_bd['nome_aps']."',
'".$linha_bd['codigo_aps']."',
'".$linha_bd['uf_aps']."',
'".$linha_bd['nome_gex']."',
'".$linha_bd['codigo_gex']."',
'".$linha_bd['data_intimacao']."',
'".$linha_bd['data_distribuicao']."',
'".$linha_bd['data_audiencia']."',
'".$linha_bd['processo_prazo']."',
'".$linha_bd['processo_destino']."',
'".$linha_bd['assunto']."',
'".$linha_bd['cod_assunto']."',
'".$linha_bd['localizacao']."')";
}
$sql=substr($sql,0,strlen($sql)-1); 

require_once("../frameworks/AS_lib/as_Lib_banco_de_dados.php");
$banco_de_dados=new banco_de_dados();
$banco_de_dados->executa_sql($sql);

Variable contents $ sql:

  

INSERT INTO processes (process, benefit_number,             author, cpf, nit, date_name, name_mae,             name_aps, code_aps, uf_aps, name_gex, code_gex,             date_intimacao, date_distribution, date_audience,             process_date, target_process, subject, cod_provider,             location) VALUES (       '00000022620154036304',       '0006660000',       'ROMILDO CARLOS RIBEIRO MENDES',       '12585255859',       '',       '1969-02-22',       'ROSILDA MATOS MENDES',       '',       '',       '',       '',       '',       '2015-03-10',       '2015-01-15 13:07:30',       '2015-09-21 14:45:00',       '2015-04-09',       '',       '040104 - SPECIAL RETIREMENT (ART 57/8) - BENEF. IN SPECIES / CONCESSION / CONVERSION / RESETTLEMENT / COMPLEMENTATION ',

Error:

  

"Invalid SQL: 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

    
asked by anonymous 10.03.2015 / 19:04

1 answer

3

When you have n values in a insert , these must be separated by commas:

insert into [table_name] (column_1, column_2, ...)
values (value_1, value_2, ...), (value_3, value_4, ...)

In your code you apparently want to do this, you even make a substring to remove the comma after foreach , however you forgot to concatenate the comma at the end of each set of values:

'".$linha_bd['localizacao']."')";

Change to:

'".$linha_bd['localizacao']."'),";
    
10.03.2015 / 19:32