How to insert into the database with prepared statements? Problem with ID

1

I'm having column count problems because I do not know how to enter data by PDO when it has a id AUTO_INCREMENT that comes before the nome variable. I'm not exactly sure how to enter id along with the other data. There is an error in the column count. Can anyone help me?

$cadNome        = strip_tags($_POST['nome']);
$cadEmail       = strip_tags($_POST['email']);
$cadTelefone    = strip_tags($_POST['telefone']);
$cadCeular      = strip_tags($_POST['celular']);
$cadCidade      = strip_tags($_POST['cidade']);
$cadDatepicker  = strip_tags($_POST['datepicker']);
$cadEstimada    = strip_tags($_POST['estimada']);
$cadComentarios = strip_tags($_POST['comentarios']);
$cadData        = 'NOW()';

$stmt = $pdo->prepare('INSERT INTO wp_contato VALUES(:nome, :email, :telefone, :celular, :cidade, :datepicker, :estimada, :comentarios, :datacontato)');

$stmt->execute(array( 
                ':nome'         => $cadNome,
                ':email'        => $cadEmail,
                ':telefone'     => $cadTelefone,
                ':celular'      => $cadCeular,
                ':cidade'       => $cadCidade,
                ':datepicker'   => $cadDatepicker,
                ':estimada'     => $cadEstimada,
                ':comentarios'  => $cadComentarios,             
                ':datacontato'  => $cadData
                ));
    
asked by anonymous 24.10.2014 / 17:55

1 answer

2

Use NULL before the name parameter.

AUTO_INCREMENT will take care of the rest!

$stmt = $pdo->prepare('INSERT INTO wp_contato VALUES(NULL, :nome, :email, :telefone, :celular, :cidade, :datepicker, :estimada, :comentarios, :datacontato)');
    
24.10.2014 / 18:02