Right, I'm trying to do a select in a database via ajax using jQuery. Here are some excerpts from 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 have already checked and the connection is being made and the data is being passed correctly, however I get a return error message indicating that the select is not being done. I do not understand why this is happening and I'm a bit new to this part of creating database connections. If I have omitted any important information please ask for comments