improve my PHP user interaction
<p>I have a situation where a user fills out 1 of 2 forms on a registration page and is sent to a software download page. If they sign up as a new user, form is processed inserted into a MySQL database and they go to the page no problem.</p>

<p>Here is my issue. If they are a returning user and enter a license key, the processor script checks to see if its valid against the database and if it is it sends them to the software download page. If it is NOT a valid license key (heres what I dont like) the screen goes to the url of the script, page is white, an alert pops down telling them its not a valid license key and they are returned to the registration page to try again. I hate this. I need to figure out a way to either pop the alert on the registration page w/o leaving it or better yet display some kind of message on the page. One drawback is that the script is and always will be on a different server than my forms. Ive tried curl and had success with other situations but can't close the MySQL connection on this one. Is there another way to achieve some semblance of "cross domain AJAX" I would really like it to not go to the script url/white page/alert then return them. I would like it to happen all on one page. Here is that part of my script:</p>

<pre><code>if ($_POST['license_code'] != "")
{
    $result = mysql_query("(//mysql stuff here)");



    if (($row = mysql_fetch_assoc($result)))
    {
        header("Location: http://" . $redirect);
    }
    //here is the part I dont like
    else        
    {
        echo "&lt;html&gt;\n";
        echo "&lt;body&gt;\n";
        echo "&lt;script language=\"Javascript\"&gt;\n";
        echo "alert (\"The license ID you entered was not correct.\");\n";
        echo "window.location=\"http://www.registrationpageURL.php\";\n";
        echo "&lt;/script&gt;\n";
        echo "&lt;/html&gt;\n";
        echo "&lt;/body&gt;\n";
    }
    mysql_close($link); 
}
//I use jquery valiadate.js for CS validation, but realize this is necessary and would like it to behave like the desired result for the above
else
{
  if (strpos($_POST['email1'], '@') === false)
{
        echo "&lt;html&gt;\n";
        echo "&lt;body&gt;\n";
        echo "&lt;script language=\"Javascript\"&gt;\n";
        echo "alert (\"The email address you entered was not correct.\");\n";
        echo "window.location=\"http://www.registrationpageURL.php\";\n";
        echo "&lt;/script&gt;\n";
        echo "&lt;/html&gt;\n";
        echo "&lt;/body&gt;\n";    
  return;
}
</code></pre>

<p>thx</p>
