Send errors to PHP page in real time with jQuery
<p>I built a form in php that sends the input values to a jQuery page which then sends the information to another php page to insert the values in to the database. </p>

<p><strong>The problem is</strong></p>

<p>When there's an error, let's say the username exists, I need to be able to send a message back from the php page to the original form and have it show in real time. Any ideas on how to do this?</p>

<p><strong>Here's the jQuery</strong> that handles the submition from the form to the php page that inserts in to the database.</p>

<pre><code>// Handle account updates
$('#save_account').click(function() { 
    var log_token = $('#log_token').val();  
    var user_name = $('#user_name').val();  
    var user_pass = $('#user_pass').val();  
    $.post("php/includes/update_account.php", {
        log_token: log_token,
        user_name: user_name,
        user_pass: user_pass
    });
});
</code></pre>

<p><strong>Here's the PHP</strong> that inserts the values in to the database.</p>

<pre><code>$log_token = $_POST['log_token'];
$user_name = $_POST['user_name'];
$user_pass = $_POST['user_pass'];

$db = db_open();
$query = "SELECT user_name FROM users WHERE user_name='$user_name'";
$result = db_query($db, $query);
$result = db_num_rows($result);
if (!$result) {
    $query = "UPDATE users SET user_name='$user_name', user_pass='$user_pass' 
        WHERE user_id='$_SESSION['user']['user_id']'";
    $result = db_query($db, $query);
} else {
    Pass Error to FORM HERE
}
db_close($db);
</code></pre>
