0
I’m making a Insert field input in the database using ajax and PHP. In the code below I am returning to the ajax a success message if all goes 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");
I tested it here and it worked exactly as I wanted. Thanks for the help friend!
– Eduardo Ribeiro