Show Alert or message after a header? PHP

5

I was creating a insert , and when I sent the data I got an alert message saying that the data had been inserted successfully, but now, the page goes blank and only shows that alert.

What I did to keep it from getting stuck was to redirect again with header , only this time I do not get the message or the alert.

It's very simple I guess, I put it before and after the header and it did not work.

if ($mail->send()) 
{

  header("location:controlador.php");

  echo '<p class="alert alert-success agileits" role="alert">Captura realizada correctamente!p>';

  } else {

  echo "Mailer Error: " . $mail->ErrorInfo;
}
    
asked by Jonathan 09.08.2017 в 21:43
source

2 answers

3

to print an alert inside php do it this way:

<?php 
     echo "<script>
                alert('Mensaje');
                window.location= 'url.php'
    </script>";
?>
    
answered by 09.08.2017 / 21:47
source
2

Using PHP and the method header , you could solve it like this:

if ($mail->send()) {

  // Recargar la página despues de 10 segundos y redireccionar a "controlador.php"
  header('Refresh: 10; URL=controlador.php');

  echo '<p class="alert alert-success agileits" role="alert">Captura realizada correctamente!p>';
} else {

  echo "Mailer Error: " . $mail->ErrorInfo;
}
  

Remember that header () should be called before displaying anything on the screen, HTML tags, blank lines from a file or from PHP.

    
answered by 09.08.2017 в 22:07