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.
 
     
    