How to insert the ID in the bank since it is the first field of the table?

1

I have auto increment ID and am having error counting columns with this code. How do I enter the ID together?

    #SQL Execute
    $uir = $pdo->prepare("INSERT INTO visitados VALUES (:IMO_CODIGO, :CATEGORIA, :BAIRRO, :FOTO_PRINCIPAL, :VLR_VENDA, :AREA_TOTAL, :DORMITORIO, :DATA)");

    $uir->bindParam(':IMO_CODIGO', $imov);
    $uir->bindParam(':CATEGORIA', $cate);
    $uir->bindParam(':BAIRRO', $bair);
    $uir->bindParam(':FOTO_PRINCIPAL', $foto);
    $uir->bindParam(':VLR_VENDA', $vlrv);
    $uir->bindParam(':AREA_TOTAL', $area);
    $uir->bindParam(':DORMITORIO', $dorm);
    $uir->bindParam(':DATA', $adata);

    $uir->execute();
    
asked by anonymous 29.09.2014 / 23:54

2 answers

3

You need to explicitly declare the name of the columns that INSERT will be doing if you want to omit some field, eg

INSERT INTO visitados (nomecoluna, outronomecoluna, maisumnomecoluna ...) VALUES (:IMO_CODIGO, :CATEGORIA, :BAIRRO ...)
    
30.09.2014 / 00:26
3

No doubt it's best to declare the field names as response from wryel , even if you do not need to obey the exact order in the table.

But for information, it would also work like this:

#SQL Execute
    $uir = $pdo->prepare("INSERT INTO visitados VALUES (NULL, :IMO_CODIGO, :CATEGORIA, :BAIRRO, :FOTO_PRINCIPAL, :VLR_VENDA, :AREA_TOTAL, :DORMITORIO, :DATA)");
    
30.09.2014 / 01:54