Does not redirect

Asked

Viewed 44 times

0

I have the code below right at the top of a page. I am going to it without passing ID through GET, so you are entering ELSE correctly. It is going through setFlash, but does not redirect the page through Location. It stays on the same page. What can be?

<?php 
    if(!empty($_GET['id'])){
        $id = $_GET['id'];
        $estabelecimentoDao = new EstabelecimentoDAO(); 
        $estabelecimentos = $estabelecimentoDao->all(); 
        $agendaDao = new AgendaDAO();
        $teste = $agendaDao->first($id);
    }else{
        $flash = new Flash();
        $flash->setFlash('Para editar você precisa passar um ID Válido</br>', 'alert-danger');
        header('Location:../../View/Agenda/index.php');
    }
?>
  • this code is by inserting on a larger page? I say the header has already been sent? I believe I can only redirect before sending the header

  • header won’t work if you have any code printed on the screen.

  • That was it. Thank you :D

1 answer

0

According to PHP documentation:

Remember that header() needs to be called before any content whether sent by HTML tags, blank lines in a file or from PHP itself.

So, do not alert on the screen, because the header will not work.

Browser other questions tagged

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