I wanted to put an Alert on my login screen

Asked

Viewed 61 times

2

I wish that when I hit login and my password or registration, did not match what is not in the bank he of some Alert. here is 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;

    }




}

Here Is 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"); 
    }

}





?>

Here is 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>
  • Why is the return id and the nome in the authenticate function? If goal-oriented Foss, it would be advisable to store this data in a variable privada and get them through gets() and in its function autenticar, would return a boolean to identify if the user exists or not. Not to mention that you have the model but it doesn’t have the controller.

  • I have my full MVC, but where does Alert stand on the model or Controller ? I’ll put the Controller.

  • How are you making your call view in control? By what I saw, you’re just redirecting to a certain page. That’s right?

  • Remember, every visual part is always in your view

  • type I am using this " header("Location: http://localhost/project/student.php"); ", for when the registration and password have right(match what is in the bank), is there something wrong with me doing so ? It’s not long since I’ve been studying MVC.

1 answer

-1

Place this code in PHP when you want Alert to be displayed:

Echo "<script>alert('Menssagem');</script>";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.