How to avoid double submission of a form when updating the page?

Asked

Viewed 110 times

0

I have this function that is responsible for performing the registration of a new user in my form, so when I update it I re-enter the last record, how can I do the treatment so that it does not happen?

   function cadastrarUsuario ($conexao, $titulo){
    //verificando se o formulário foi postado
    if(isset($_POST['frmCadUsuario'])){
        //postou o formulario)
        $usuario = $_POST['txtNomeUsuario'];
        $idade = $_POST['txtIdadeUsuario'];

       if (usuario_cadastrar($conexao, $usuario, $idade));{
            $retornoEsc = "Usuário Cadastrado com Sucesso!";
            $dados = listarDados($conexao);
            require ("view_lista.php");
        }

    }
    else{
        //mostrar o formulário de cadastro
        require ("view_form_cadastro_novo_usuario.php");
    }
}
  • In the other questions I could not get an answer that showed the definitive solution, I tried a few examples and did not succeed.

  • The solution I found for my problem was to add before the '$returns Sc = "Successfully Registered User!" ;' the following: 'header("Location: http://here the address you want to return"); Exit;' In the answers I got in the duplicate questions they were not needed to understand where the header should be added

No answers

Browser other questions tagged

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