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.
The problem is
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?
Here's the jQuery that handles the submition from the form to the php page that inserts in to the database.
// 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
});
});
Here's the PHP that inserts the values in to the database.
$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);