$status = 'ok'; if (isset($_POST['id_hidden'])) { //Update if (!$employee->update($connection)) { //Error $error = $connection->lastError(); if ($error['errno'] == 1062) { //UQ value error $status = "repeat"; } else { $status = "Error {$error['errno']}: {$error['error']}"; } } } else { //Insert if (!$employee->insert($connection)) { //Error $error = $connection->lastError(); if ($error['errno'] == 1062) { //UQ value error $status = "repeat"; } else { $status = "Error {$error['errno']}: {$error['error']}"; } } } /*XML transaction result.*/ header('Content-Type: text/xml'); echo '<transaction> <status>' . $status . '</status> </transaction>