1
I wanted to put an Alert on my login screen, if the registration and password match what’s in the bank pass straight, if not, an Alert appeared or the boxes were red with the error with something like "Wrong registration or password"
There’s the connection to my bank
<?php
$username = 'root';
$password = '';
$connection = new PDO( 'mysql:host=localhost;dbname=nise', $username, $password );
?>
My Controller
<?php
include 'usuarios/modelUsuario.php';
//se clicou no botão
if (isset($_POST['login'])){
$modelo = new ModelUsuario();
$resultado = $modelo->autenticar( ($_POST['matricula']), ($_POST['senha']) );
if(! empty($resultado) ){
// redirecionar para index2
header("location: http://localhost/projeto/aluno.php");
}
}
?>
The model
<?php
include 'usuarios/usuario.php';
class ModelUsuario{
public function adicionar(){
include 'usuarios/bd.php';
$query = "INSERT INTO usuarios (matricula, senha)
VALUES (:matricula, :senha)";
$statement = $connection->prepare($query);
$valores = array();
$valores[':matricula'] = $usuario->getMatricula();
$valores[':senha'] = $usuario->getSenha();
$result = $statement->execute($valores);
}
public function editar(){
}
public function remover(){
}
public function autenticar($matricula, $senha){
include 'usuarios/bd.php';
$query = "SELECT nome, id FROM usuario WHERE matricula=:matricula and senha=:senha";
$statement = $connection->prepare($query);
$valores = array();
$valores[':matricula'] = $matricula;
$valores[':senha'] = $senha;
$result = $statement->execute($valores);
$result = $statement->fetchAll();
return $result;
}
}
?>
And my form
<form method="POST" action ="login.php" name="for">
<div class="form-group">
<div class="form-label-group">
<input type="text" id="inputEmail" name="matricula" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Matrícula</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" name="senha" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Senha</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me">
Lembrar senha
</label>
</div>
</div>
<button type="submit" class="btn btn-primary btn-block" href="aluno.php" name="login">Login</button>
<a href="registro.php" id="cadastro" class="d-block small mt-3">Cadastrar</a>
</form>
NOTE: ALERT CAN BE IN JS OR AJAX, SO HELP ME.