I'm developing an application where the user types some information, two of them are CodeMotorist and CodeVeiculo.
This is an excerpt from my code:
try {
$database->query($sql);
$_SESSION['message'] = 'Registro cadastrado com sucesso.';
$_SESSION['type'] = 'success';
} catch (Exception $e) {
$_SESSION['message'] = 'Não foi possivel realizar a operação.';
$_SESSION['type'] = 'danger';
}
I am able to make the normal registrations, the problem is that when the user informs a Motorist Code or Vehicle Code that does not exist the system does not give Exception (It should give an Exception because these data are Foreign Keys) the system does not do the same insertion, what I need is to adapt this code to give an Exception with the error or change the parameter of the condition, to inform the user that the registration gave an error.