0
I created a table "usuario"
in the MySQL
containing name and password. I have established a connection with the PHP
and I would like to consult on AJAX
, to validate this name and password and print a message saying if they are valid or not. But I do not know how to do the part of the query 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);
?>
You want to know if the user exists or not, that’s it?
– Woton Sampaio
Ué, you make the connection with OO and dps goes to procedural, masoq
– Woton Sampaio