0

I wanted to popup an alert box. After that, the site would redirect to main page. But, it seems that it directly redirect to the mainpage without alerting anything.

if($registerquery)
    {
    ?>

    <script>alert('received!')</script>
<?php
    }


    header("Location: mainpage.php");
    exit();


    ?>

I wanted to do this to ensure users that the process of submission ended successfully. How can i alert something before the page redirect to mainpage and more importantly what causes this? I think the page should not have redirected before the alert box.(Before these codes, site registers what users submitted but not relevant i guess.)Thanks

1 Answer 1

5

You just can't do this. PHP is server-side, JS is client-side. Using a location header is server-side, so the browser never gets the JS.

Instead, try something more like:

if( $registerquery)
    echo "<script>alert('received!'); location.href='mainpage.php';</script>";

and remove the header bit altogether.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.