Help with displaying Errors in PHP
<p>I have a routine I would like to streamline. Currently on my registration page you can either enter a key (returning user) or sign up. Once you fill out a form, the form is processed by a script on another server (includes some CRM database inserts so it has to be on the same server as the CRM) I am doing client side validation with jQuery, but the SS validation checks the license key to make sure its valid. If it is in valid it does the following - changes the URL to the processor URL, displays an alert with error message and returns you to the registration page. I hate this.</p>

<pre><code>if (($row = mysql_fetch_assoc($result)))
    {
        header("Location: http://" . $redirect);
    }
    else        
    {
        echo "&lt;html&gt;\n";
        echo "&lt;body&gt;\n";
        echo "&lt;script language=\"Javascript\"&gt;\n";
        echo "&lt;!--\n";
        echo "alert (\"The NinjaTrader license ID you entered was not correct.\");\n";
        echo "window.location=\"http://www.dirtybirddesignlab.com/download-registration.php\";\n";
        echo "//--&gt;\n";
        echo "&lt;/script&gt;\n";
        echo "&lt;/html&gt;\n";
        echo "&lt;/body&gt;\n";
    }
    mysql_close($link); 
}
</code></pre>

<p>I did not write this, and want to improve upon it. I would prefer it display a processing msg, make the check and if it is an invalid code, display that message above or in the form. Would this require cURL due to same origin policy/cross domain? I use cURL in several other areas but can't get this to work, i get errors relating to not closing the MySQL connection. Is there a simpler way to fix the above code to simply "print" to the page an error msg with out changing url and displaying alert? thanks experts!</p>
