0
Warning: Pdostatement::execute(): SQLSTATE[HY093]: Invalid Parameter number: number of bound variables does not match number of tokens in C: xampp htdocs teste all_processo.php on line 92
Error line:
$conexao->beginTransaction();
try{
$sql = "INSERT INTO processos (proc_id, numero, assunto, requerente, status)
VALUES(:proc_id, :numero, :assunto, :requerente, :status)";
$sql = "INSERT INTO informes (inf_id, de_setor, para_setor, informe, data, informante, processo_id)
VALUES (:inf_id, :de_setor, :para_setor, :informe, :data, :informante, :processo_id)";
$stm = $conexao->prepare($sql);
$stm->bindValue(':proc_id', $proc_id);
$stm->bindValue(':numero', $numero);
$stm->bindValue(':assunto', $assunto);
$stm->bindValue(':requerente', $requerente);
$stm->bindValue(':status', $status);
$stm->bindValue(':inf_id', $inf_id);
$stm->bindValue(':de_setor', $de_setor);
$stm->bindValue(':para_setor', $para_setor);
$stm->bindValue(':informe', $informe);
$stm->bindValue(':data', $data);
$stm->bindValue(':informante', $informante);
$stm->bindValue(':processo_id', $processo_id);
$retorno = $stm->execute(); //LINHA 92
if ($retorno):
echo "<div class='center1' role='alert'>Processo inserido com sucesso, aguarde você está sendo redirecionado...</div> ";
echo "<div class='loader'</div>";
else:
echo "<div class='center1' role='alert'>Erro ao inserir processo, aguarde!</div>";
echo "<div class='loader'</div>";
endif;
echo "<meta http-equiv=refresh content='4;URL=listarprocessos.php'>";
$conexao->commit();
}
catch(Exception $e){
echo $e->getMessage();
$conexao->rollBack();
}
You’re declaring twice var
$sql
, and the second is the one that will prevail, and does not have the same number ofVALUES
that yoursbindValue
– Miguel
For this I made the transaction. should I put $sql and $sql2? (for example)
– Bernardo Rodel
No, in the second
$sql
you do$sql .= "INSERT
...– Roberto de Campos
and take the transaction? thanks in advance.
– Bernardo Rodel
you need to do two separate Inserts and the backups.
– rray
I did as follows: $sql = "INSERT INTO processes(proc_id, number, subject, requester, status) VALUES(:proc_id, :number, :subject, :applicant, :status)"; $stm = $connected->prepare($sql.="INSERT INTO informes(inf_id, de_sector, para_sector, inform, date, informant, processo_id) VALUES (:inf_id, :de_setor, :para_setor, :informe, :data, :informante, :processo_id)"); .
– Bernardo Rodel
you have to do something like
$processos = 'insert .... values (:id, :nome)';$stm->prepare($processos); if($stm->execute()){ $informes = 'insert .... values (:outroId, outroNome)'; $stm->preapre($informes) ....
. See that now has two variables of Insert, two calls fromprepare()
andexecute()
just don’t forget to make the Binds before the run.– rray
after doing what you said, @rray, is recording twice the same data.
– Bernardo Rodel
I believe it is better to create a new question already the code has changed and the error too.
– rray
OK, but there is no visible error
– Bernardo Rodel