How to insert into bank with Prepared statements? Problem with ID

Asked

Viewed 43 times

1

I’m having trouble counting columns because I don’t know how to input the data by PDO when you have a id AUTO_INCREMENT that comes before the variable nome. I don’t know exactly how to insert the id along with the other data. Ai gives error in column count. Someone can 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
                ));

1 answer

2

Utilize NULL before the name parameter.

The AUTO_INCREMENT takes care of the rest!

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

    Already solved. Just waiting for the system to authorize to mark as best answer. Thank you.

  • Show! Any questions just ask!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.