Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Fatal error: Call to undefined method User::get_user_data() php oop

i get Fatal error: Call to undefined method User::get_user_data() when i call User::get_user_data function on my login page

$user_found = User::get_user_data($username, $password);

my function is

public static function get_user_data ($username , $password)
{
    $mysqli = new mysqli("localhost", "*****", "****", "*****");
    if ($mysqli->connect_error){
        printf("Connect failed: %s\n", $mysqli->connect_error);
        exit();
    }

    $user = mysqli_real_escape_string($mysqli,$username);
    $pass = mysqli_real_escape_string($mysqli,$password);

    $result = $mysqli->query($mysqli,"SELECT * FROM users where username  = '$user' and password = '$pass' LIMIT  1");
    return !empty($result) ? array_shift($result) : FALSE;
}

what i do wrong

i just update a bit my code but still have issue i add create config.php and i define all my database connection details to Constants.

i create new class Database and all my functions related with db there

i create a function

public function open_db_connection() {

    $this->connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    if ($this->connection->connect_errno) {
        die('database Connection Failed' . $this->connection->connect_error);
    }
}

to open db connection

and i create query function to load my queries

public function query($sql) {
    $result = $this->connection->query($sql);
    $this->confirm_query($result);
    return $result;
}

then i update my get_user_data function

    public static function get_user_data ($username , $password)
    {
        global $database;

        $user = mysqli_real_escape_string($database->connection , $username);
        $pass = mysqli_real_escape_string($database->connection , $password);

        $result = $database->query("SELECT * FROM users where username  = '$user' and password = '$pass' LIMIT  1");

        if (!empty($result)) {
            return array_shift($result);
        } else
            return false;
    }

and now i get other error

Warning: array_shift() expects parameter 1 to be array, object given

Comments