I created a "usuario"
table in MySQL
containing name and password. I established a connection with PHP
and would like to query for AJAX
, to validate this name and password and print a message saying whether they are valid or not. But I do not know how to do the query part in the inputs.
<html>
<head>
<title>Exercício Tec Prog I</title>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script>$(document).ready(function(){$("#bEntrar").click(function(){
fLogar();
});
function fLogar()
{
$.ajax({
type: 'POST',
dataType: "json",
url: "usuario.php",
success:function(dados)
{
}
});
</script>
</head>
<body>
<form action="usuario.php" method="POST">
<label>Usuario</label>
<input type="text" id="tLogin"/>
<label>Senha</label>
<input type="text" id="tSenha">
<button id="bEntrar">Entrar</button>
<div id="divFilmes"></div>
</form>
</body>
</html>
<?php
$tLogin = $_POST["tLogin"];
$tSenha = $_POST["tSenha"];
//Conectando ao banco de dados
$con = new mysqli("localhost", "root", "root", "tecprog");
if (mysqli_connect_errno()) trigger_error(mysqli_connect_error());
//Consultando banco de dados
$qryLista = mysqli_query($con,"SELECT * FROM usuario WHERE nome = '$tLogin' AND senha = '$tSenha'");
while($resultado = mysqli_fetch_assoc($qryLista)){
$vetor[] = array_map('utf8_encode', $resultado);
}
//Passando vetor em forma de json
echo json_encode($vetor);
?>