user3846091
user3846091

Reputation: 1703

php header redirect does not display contents?

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;

Upvotes: 0

Views: 60

Answers (3)

Logar
Logar

Reputation: 1248

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

Upvotes: 1

Joey Emery
Joey Emery

Reputation: 684

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).

Upvotes: 0

may saghira
may saghira

Reputation: 564

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

Upvotes: 1

Related Questions