Double insertion with mssql_query

Asked

Viewed 166 times

1

I am having a small problem and would like help to solve it. I have a code that makes the insertion into a SQL SERVER database through php. Everything is fine, except that two "INSERT" in the bank are being made. I can’t see what’s wrong, so I wish someone could help me

The $upload variable is triggered as soon as the form is sent. I don’t even know why this double INSERT :(

if($envio){

$pastaupload = 'candidatos/';
$arquivoupload = $pastaupload .  time() . $_FILES['arquivo']['name'];   

move_uploaded_file($_FILES['arquivo']['tmp_name'], $arquivoupload );
$caminho = "http://meusite.com.br/".$arquivoupload;

$insert ="INSERT INTO CANDIDATO (NOME, DH_NASCIMENTO, CEP, ENDERECO, NUMERO, BAIRRO, MUNICIPIO, UF, TELEFONE, CELULAR, EMAIL, CD_SEGMENTO_CARGO, OBSERVACAO, PATH_CURRICULO, CD_STATUS, CD_USUARIO) VALUES ('$nome', '$datanascimento', '$cep', '$endereco', '$numero', '$bairro', '$cidade', '$uf', '$telefone', '$celular', '$email', $segmento, '$observacoes', '$caminho', 1, 12 )";

mssql_query($insert);

mssql_close($connection); 

}
  • Double click on Ubmit? You can use email as Unique key to avoid duplicate records.

  • 1

    This question already has answer somewhere, let me look for the link.

  • The only problem was that the user did not choose an answer, so he was unable to mark it as repeated/related - http://answall.com/questions/10744/como-n%C3%A3o-record-duplicate-in-mysql-com-php/10745#10745

2 answers

2

I figured out what was going on, I was using a function to upload the files, the move_uploaded_file().

It was she who was causing the record to be entered twice. I just put her inside an if and it worked!

I have tested what you have suggested to me, thank you very much for your attention!

1


Check that the form is not being submitted twice. A good way to do this is to take the mssql_query and simply make a echo "Test"; or something appeared.

If you can’t, try using the Developer Tools, available in multiple browsers. There is usually a way to see the submissions made.

Browser other questions tagged

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