0

I am trying to display the alert statement once insert is done in mysql database. However, it would insert and immediately redirect to the webpage. It would not display anything between that ? Is there a better way to display message then redirect ? I even tried sleep function.

mysqli_query($con,"INSERT INTO invite_email (email) VALUES ( '".trim($email)."') ");

echo "<script> alert(\"Congratulations! We will contact you soon when the app is launched \") </script>";

mysqli_close($con);

echo " Please wait you will now be redirected to www.xyz.com website";

sleep(5);
header("Location: http:/www.xyz.com");
exit;
user3846091
  • 1,625
  • 6
  • 24
  • 29

3 Answers3

1

you're missing '/' in the "Location:http://www.nomsite.com"

may saghira
  • 564
  • 9
  • 16
1

from php documentation :

Remember that header() must be called before any actual output is sent

This link might be useful to you

Edit : As Joey Emery said, doing this entirely in js should work as well, and maybe a simpler solution than the link i posted

Community
  • 1
  • 1
Logar
  • 1,248
  • 9
  • 17
0

Would it not be easier to do this entirely in Javascript?

$('body').append('<p>Please wait you will be redirected.... (If you arent, click <a href="#">here</a></p>');

setTimeout(function() {
    window.location.href = 'http://www.website.com';
}, 5000);

(Yes this example uses jQuery, but only for appending the p tag).

Joey Emery
  • 684
  • 2
  • 6
  • 15