0
Okay, I’m trying to select a database through ajax using jQuery. Below are excerpts of the code I’m using and more explanations:
Ajax function
function carregaRegistros(dia, mes, ano) {
dia = parseInt(dia);
mes = parseInt(mes);
ano = parseInt(ano);
$.ajax({
method: "POST",
url: "PHP-Files/carregaRegistros.php",
data: {dia: dia, mes: mes, ano: ano},
success: function(result){
alert(result);
}
});
}
Query
// Cria conexão
$conn = new mysqli($servername, $username, $password, $dbname);
// Verifica conexão
if ($conn->connect_error) {
die("Erro de conexão: " . $conn->connect_error);
}
$dia = $_POST["dia"];
$mes = $_POST["mes"];
$ano = $_POST["ano"];
$sql = "SELECT Cliente, TotalDeHoras, HoraDeEntrada, HoraDeSaida FROM
apontamentos WHERE Dia='$dia' AND Mes='$mes' AND Ano='$ano'";
if ($conn->query($sql) === TRUE) {
echo "Apontamento incluído com sucesso!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
I already checked and the connection is being made and the data is being passed correctly, however I get an error message as return which indicates that the select is not being done. I don’t understand why this is happening, and I’m kind of new at this part of creating database connections. If I have omitted any important information please ask in the comments
What error is being returned?
– Roberto de Campos
Error: SELECT Customer, Totaldehoras, Horadeentrada, Horadesaida FROM notes WHERE Dia='1' AND Mes='5' AND Ano='2018'<br>
– Guilherme Bartasson
If any answer solved your problem be sure to report it as accepted, see https://i.stack.Imgur.com/evLUR.png and because https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-accepta reply/1079#1079
– user60252