1
I have a login page, in which there is a form, which sends the data of two fields (username and password) to a PHP file that checks. This php file uses a function already written in a class. In this function, if the result is true, a redirect happens, if it is not, it will execute a Jquery code to display an "Invalid Password" message there in the login page. The intention is that this Jquery changes the property of a certain element from "Hidden" to "Visible", thus presenting the message on the screen.
I’m a little confused, and I’ve never really got it right with jQuery, and I don’t know if I’m missing any important details, so I’d like a good soul to give me a hand. Follows the codes HTML:
<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Login</title>
<meta http-equiv="content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/login_style.css">
</head>
<body>
<div class="login-page">
<div class="form">
<form class="login-form" action="verificacaologin.php" method="post">
<input type="text" placeholder="Usuário" name="nome_usuario"/>
<input type="password" placeholder="Senha" name="senha"/>
<button type="submit">login</button>
</form>
<label class="senha_incorreta">Senha incorreta.Tente novamente.</label>
</div>
</div>
</body>
</html>
Php doing the checking:
<?php
include_once 'classes/Usuario.php';
$nome = $_POST['nome_usuario'];
$senh = $_POST['senha'];
$usuario = new Usuario();
$usuario->verificarExistenciaLogin( $nome , $senh);
?>
Function of the User class containing Jquery:
public function verificarSenhaCorreta( $nome_usuario , $senha )
{
$query = "select SENHA from portfolio.usuario where NOME_USUARIO = '$nome_usuario' ";
$conexao = new Conexao();
$resultado_consulta = $conexao->abrirConexao( $query );
$resultado_consulta = implode($resultado_consulta);
if( $resultado_consulta == $senha )
{
header("Location:ordem_servico.php");
}
else
{
//mostrar mensagem de que a senha está incorreta();
?>
//Aqui que minhas dúvidas começam
<script>
$(document).ready(function()
{
$('.senha_incorreta').css( "visibility" , "visible" );
});
</script>
<?php
}
}
There is no "PHP page". PHP can even generate a page, but after it is sent to the client it is the same as any other. However, since in PHP you have control over what will be sent, it makes much more sense to send the correct information to the user. EVENTUALLY you can load the data via AJAX or any other interactive method, but this does not matter what technique you will use in JS (if it is pure JS, if it is jQuery, or whatever you choose)..
– Bacco
PHP is a script that, in addition to other features, generates HTML that in turn can import or have Javascript
– Sveen
From what I saw in your code you didn’t reference the file Jquery within the HTML. I believe that when you do this will work, otherwise, try to consult through the event
onclick()
ofbutton
using the Ajax which will await the response of PHP and thus enable or disable the label.– Ronaldo Skibinski