Redirect to another page when logging error!

0

I have a registration system, which does not allow the user to register with an email already registered, but when I register with an existing email, it does not redirect the user to the registration page. I used the header='Location(cadastro.php?erro=1)' tag.

Are there any other tags that can be used? Or what could be wrong for him not to be redirecting?

Here is the php code that tries to register at the bank:

 <?php
    session_start();    
    require_once('conecta.php');

    // RECEBENDO OS DADOS PREENCHIDOS DO FORMULÁRIO !
    $nome   = $_POST ["nome"];
    $data   = $_POST ["data"];
    $email  = $_POST ["email"];
    $email2 = $_POST ["email2"];
    $senha  = $_POST ["senha"]; 


    $arq = $_FILES['foto']['name'];

    $arq = $_FILES['foto']['name'];

    $arq = str_replace(" ", "_", $arq);
    $arq = str_replace("ç", "c", $arq);

    if (file_exists("imagens/".$arq)) {
        $a = 1;

        while (file_exists("imagens/[".$a."]".$arq)) {
            $a++;
        }

        $arq = "[".$a."]".$arq;
    }

    if (move_uploaded_file($_FILES['foto']['tmp_name'], 'imagens/'.$arq)) {
        $objDb = new db();
        $link = $objDb->conecta_mysql();
        $sql = "insert into voluntarios (nome, data, email, email2, senha,  foto) values ('$nome', '$data', '$email', '$senha', '".$arq."')";
        if (mysqli_query($link, $sql)){


            echo '<nav class="navbar navbar-fixed-top navbar-inverse navbar-transparente">
              <div class="container">
                <!-- Header -->
                <div class="navbar-header">
                  <!-- botao toggle -->
                  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#barra-navegacao">
                    <span class="sr-only">Alternar navegação</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </button>

                  <a href="index.php" class="navbar-brand">
                    <span><img src="imagens/logoviladobem.png" width="80px"></span>
                  </a>
                </div>
                <!-- navbar -->
                <div class="collapse navbar-collapse" id="barra-navegacao">
                  <ul class="nav navbar-nav navbar-right">
                    <li><a href="sobre.php">Sobre</a></li>
                    <li class="divisor" role="separator"></li>
                    <li><a href="facaparte.php">Faça Parte</a></li>
                    <li><a href="entrar.php">Entrar</a></li>
                  </ul>
                </div>
              </div>
            </nav>

            <div class="capa">
              <div class="texto-capa">
                <h1>Parabéns por ter tido essa inciativa, seu cadastro foi realizado com sucesso!</h1>
                <h3>Um e-mail foi enviado para o e-mail cadastrado com algumas informações importantes.</h3>
              </div>
            </div>';
        } else {
            header('Location: cadastro.php?erro=1');
        }

    } else {
        header('Location: cadastro.php?erro=1');
    }



    ?>
    
asked by anonymous 17.11.2017 / 15:06

1 answer

0

Setting another header alone is not enough to redirect. Try this:

else {    header ('Location: cadastro.php? error = 1');    exit (); }

    
17.11.2017 / 15:27