Satisfaction survey form

Asked

Viewed 391 times

0

I am with a following doubt, because I set up a search form and unfortunately it is not inserted in the database, I am possibly missing something.

PHP code of registration -->

<?php
include_once 'conexao.php';
if(isset($_POST['cadastrar']) && $_POST['cadastrar'] == 'sim');
  $novos_campos = array();
  $campos_post = $_POST['campos'];

  $respostas = array();
  foreach($campos_post as $indice => $valor){
    $novos_campos[$valor['name']] = $valor['value'];

  }if(!strstr($novos_campos['cpf']) <> 11){
     $respostas['erro'] = 'sim';
     $respostas['getErro'] = 'Insira corretamente o cpf...';

   }elseif(!strlen($novos_campos['telefone']) <> 11){
     $respostas['erro'] = 'sim';
     $respostas['getErro'] = 'Insira seu telefone corretamente...';

   }elseif(!strstr($novos_campos['email'], '@')){
     $respostas['erro'] = 'sim';
     $respostas['getErro'] = 'E-mail invalido...';

   }else{
     $respostas['erro'] = 'nao';
     $inserir_banco = $con->prepare("INSERT INTO pesquisa_satisfacao SET nome = ?, cpf = ?, telefone = ?, email = ?, nota = ?, nota_comentario = ?, relacao_hospital = ?, servicos = ?, alaviacao_1 = ?, avaliacao_2 = ?, avaliacao_3 = ?, final_comunicar = ?, sugestao = ?");

     $array_sql = array(
       $novos_campos['nome'],
       $novos_campos['cpf'],
       $novos_campos['telefone'],
       $novos_campos['email'],
       $novos_campos['nota'],
       $novos_campos['nota_comentario'],
       $novos_campos['relacao_hospital'],
       $novos_campos['servicos'],
       $novos_campos['avaliacao_1'],
       $novos_campos['avaliacao_2'],
       $novos_campos['avaliacao_3'],
       $novos_campos['final_comunicar'],
       $novos_campos['sugestao'];

     );
     if(inserir_banco->execute($array_sql)){
       $respostas['msg'] = 'inserido corretamente...';
     }else{
       $respostas['erro'] = 'sim';
       $respostas['getErro'] = 'Por favor, tente mais tarde...';
     }
   }
   echo json_encode($respostas);


endif;
}?>

This way I’m doing, but at the time of insertion to bank, it does not insert.

  • Note that if you check if you are running a syntax error. Change this line: if(inserir_banco->execute($array_sql)){ For that: if($inserir_banco->execute($array_sql)){

  • then, I had already corrected, and still persists the error

  • Your array $array_sql has an error, in the last item, you are using point and comma... $novos_campos['sugestao'];

2 answers

0

if you have fixed all the errors probably the problem is in your table already checked if the table id has been added an AUTO_INCREMENT

0


I believe INSERT has an error:

INSERT INTO pesquisa_satisfacao SET nome = ?, cpf = ?, telefone = ?, email = ?, 
nota = ?, nota_comentario = ?, relacao_hospital = ?, servicos = ?,

alaviacao_1 = ?

, value_2 = ? , value_3 = ? , final_communicate = ? , suggestion = ?

  • then the code already set all the errors of writing, only q yet persirte and not be inserted

Browser other questions tagged

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