I am making an insert of an input field in the database using ajax and PHP . In the code below I am returning ajax a success message if everything happens well, but how do I return a message if there is an error?
function fInserir(){
$.ajax({
url: "php/inserirPesquisaRealizadaBanco.php",
type: "POST",
dataType: "json",
data: {pesquisa:$("#iPesquisa").val(),dia:dia,mes:mes,ano:ano},
success:function(ret){
alert(ret);
}
});
}
$pesquisa = $_POST["pesquisa"];
$dia = $_POST["dia"];
$mes = $_POST["mes"];
$ano = $_POST["ano"];
$conn = mysqli_connect("localhost", "root", "root", "prova");
mysqli_query($conn, "INSERT INTO tabelaProva(pesquisa, dData) VALUES ('$pesquisa','$ano-$mes-$dia')");
mysqli_close($conn);
echo json_encode("Sucesso");