title: Javascript alert in php script
body: <p>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. </p>
  
  <pre><code>if($registerquery)
      {
      ?&gt;
  
      &lt;script&gt;alert('received!')&lt;/script&gt;
  &lt;?php
      }
  
  
      header("Location: mainpage.php");
      exit();
  
  
      ?&gt;
  </code></pre>
  
  <p>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</p>