-4

This is it:

function password_matches($username, $password){
    //precon: user_exists($username)
    $u = $GLOBALS['conn']->real_escape_string($username);
    $q = "SELECT password FROM users WHERE username = '$u'";
    $result = mysqli_query($GLOBALS['conn'], $q);
    $result2 = mysqli_fetch_field($result);
    return ($result2 == $password);
}

If you think this should work just tell me, I know my problems could be coming form somewhere else outside this function but I think that's less likely.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

0

While there are lots of problems with the way you're doing this, you also just don't know how to use the mysqli functions properly, so I'll write an answer related to that, since you'll need to know it for other tasks.

mysqli_fetch_field returns metadata about the fields in the result, not the values. To get the actual data, use mysqli_fetch_assoc:

$row = mysqli_fetch_assoc($result2);
return $row['password'] == $password;
Barmar
  • 741,623
  • 53
  • 500
  • 612