title: PHP Javascript: Closing Popup calling parent window in background
body: <p>Let's say a parent window is <code>www.mysite.com/index.php</code> has several links. When user clicks on these links, a popup is opened. </p>
  
  <p>The popup has some forms. When the user clicks submit button, another script is called within the popup like this:</p>
  
  <pre><code>if ((isset($_POST['Complete'])) &amp;&amp; ($_POST['Complete']=='Complete')) {
      unset($_POST['Complete']);
  
      include 'result.php';
  
      return;
  }
  </code></pre>
  
  <p>The <code>result.php</code> enters the data into database and pass the result to parent window with the following</p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
      window.opener.location.href = 'submission.php';
      window.close();
  &lt;/script&gt;
  </code></pre>
  
  <p>The parent window then show the final result, update the master database and emails the users.</p>
  
  <p>Now here is the problem. </p>
  
  <ol>
  <li>User clicks the link on parents. </li>
  <li>Form opens, but user click close (browser cross button). </li>
  <li>The user then closes parent window</li>
  <li>The user then visit some other page of the site; say other.php</li>
  <li>But the master database is getting updated and the user is getting the email (All <code>null</code> values though).</li>
  </ol>
  
  <p>Since the form was never completed, the <code>result.php</code> should never be called. and if <code>result.php</code> is never called, submission.php should never be called.</p>
  
  <p>What is happening here?</p>