A
A
Andriii87782017-10-17 14:34:10
PHP
Andriii8778, 2017-10-17 14:34:10

How to get password from mysql query?

I'm trying to check user authorization. I do a check by nickname, and then I need to somehow get the password and compare.

$db = new mysqli($host, $user, $password, $database)
or die("Error " . mysqli_error($db));

$sql = "SELECT name, password FROM login WHERE name = '$login_admin->nickname'";
$res = $db->query($sql);
if($login_admin->password == $res->password){
  echo "Ok";
  }else{
   echo "faslse";
}

But there is no password data in $res (I feel that something is missing there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Sapegin, 2017-10-17
@ynblpb_spb

$sql = "SELECT name, password FROM login WHERE name = '".addslashes($login_admin->nickname)."'";
$res = $db->query($sql);
$user = $db->fetch($res);
if($login_admin->password == $user->password){
  echo "Ok";
  }else{
   echo "faslse";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question