H
H
hellcaster2018-02-20 17:28:32
PHP
hellcaster, 2018-02-20 17:28:32

Doesn't alert the user?

Does not authorize the user on the site. I'm doing a very simple blog (just for myself). When I click login, I get a white screen. Here is the code. Doesn't see any errors.

<?php 

        $data = $_POST;

        if (isset($data["do_login"])) {
          $errors = array();

          $users_log = mysqli_query($db_connect, "SELECT * FROM `users` WHERE `name` = '" . $data["login"] . "'");

          if ( $data['login'] == $users_log["name"]) {
            if (passwor_verify($data['password'], $users_log["pass"]) ) {
              # code...
            } else {
              $errors[] = "Пароль не правильний";
            }
          } else {
            $errors[] = "Користувач з таким именем не знайдений";
          }
          echo "<div style='color:red;'>" .	array_shift($errors) . "</div> <hr>";
        }

        ?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2018-02-20
@web_Developer_Victor

Good afternoon.
You already ask the second question and write that there are no errors. But you get a white screen.
So maybe you should look into the server logs, the browser console, turn on error output to the browser? Raise, finally, the level of displayed errors.
It also does not hurt to arrange checks in the code.
There, you look, and the error will come out and you will figure out your problem yourself ...
ps
You can start with what is wrong here.

$data = $_POST;
        if (isset($data["do_login"])) {

It would be more correct
if (isset($_POST)) {
    $data = $_POST;
    // остальной Ваш код
}

pss
I changed your code a bit and tried to run it.
$users_log = mysqli_query($mysqli, "SELECT * FROM `users` WHERE `username` = 'administrator'");

if ($users_log["username"] == 'administrator') {
  if (passwor_verify($data['password'], $users_log["pass"]) ) {
  # code...
  } else {
    $errors[] = "Пароль не правильний";
  }
} else {
  $errors[] = "Користувач з таким именем не знайдений";
}
echo "<div style='color:red;'>" .	array_shift($errors) . "</div> <hr>";

And as a result, something appeared that you do not want to adjust in any way!
Here is the documentation , read it and do it right.

D
Dmitry Baskakov, 2018-02-20
@dmitrybascacov

Or maybe the data is not the same? MB action is not the same. Or method is not equal to post. And the mb names are specified in the id, and not in the name attributes of the inputs, which also happens <form>...</form>

M
metallix, 2018-02-20
@metallix

if (passwor_verify($data['password'], $users_log["pass"]) ) {
              # code...
            }

'passwor_verify' misspelling in function name, password_verify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question