0

i have a problem regarding mysql_result() the error message is

Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\project\classes\User.php on line 23

i know that there's many questions like this here that had been answered, i tried everything but it still give me this error

this is my User class

<?php
class User {

    public function login($logindata = array()) {
        $user_type = $this->get_user_type($logindata['user_username']);

        $this->logindata = Sanitize::escape($logindata);

        echo $user_type;

        print_r($this->logindata);
    }

    private function get_user_type($username) {
        $this->username = Sanitize::escape($username);

        $querytype = mysql_query("
            SELECT `user_type`
            FROM `ei_users`
            WHERE `user_username` = '$this->username'
        ");

        return mysql_result($querytype, 0, 'user_type');
    }
}

i already tried return mysql_result($querytype, 0, 'user_type'); but still the same error. can someone know how to solve this? thanks in advance - Peace

Peace
  • 296
  • 2
  • 13

1 Answers1

0

mysql_query() is failingwith an error. Do not use mysql_ functions, they are deprecated. Use PDO or mysqli instead. Look at the warning here http://php.net/mysql_query

But, as a quick fix

$res = mysql_query($sql);
if(!$res) {
    $error = mysql_error();
    //do something with the error
}else{
    return mysql_result(...
}
Jan Sverre
  • 4,471
  • 1
  • 21
  • 26