0

I am new to PHP PDO. I have been struggling to solve this error on my code Uncaught Error: Call to a member function query() on string in my eyes the code seems fine unless its out of my knowledge

I have a login form that the user uses to register and a file named onRegister.php that creates an object using the class manageUsers.php, onRegister checks availability of the username using a method in manageUsers class called getUserInfo every time the query in this method has to be executed an error is thrown

......manageUsers.php

include_once('class.database.php');

class manageUsers{

    public $link;

    function __construct(){

        $dbConnect = new dbConnection();
        $this->link = $dbConnect->connect();
        return $this->link;
    }

    function registerUsers($email, $password, $date){

        $query = $this->link->prepare("INSERT INTO users (username,password,date_created) VALUES (?,?,?)");
        $values = array($username,$password,$date);
        $query->execute($values);
        $count = $query->rowCount();
        return $count;

    }

    function loginUser($username, $password){

        $query = $this->link->query("SELECT * FROM users WHERE username='$username' AND password='$password'");
        $rowCount = $query->rowCount();
        return $rowCount;

    }

    function getUserInfo($username){

        $query = $this->link->query("SELECT * FROM users WHERE username  = '$username'");
        $rowCount = $query->rowCount();

        if($rowCount == 1){

            $results = $query->fetchAll();
            return $results;

        }
        else{
            return $rowCount;
        }
    }
}

?>

....onRegister.php

<?php

include_once('class.database.php');

class manageUsers{

    public $link;

    function __construct(){

        $dbConnect = new dbConnection();
        $this->link = $dbConnect->connect();
        return $this->link;
    }

    function registerUsers($email, $password, $date){

        $query = $this->link->prepare("INSERT INTO users (username,password,date_created) VALUES (?,?,?)");
        $values = array($username,$password,$date);
        $query->execute($values);
        $count = $query->rowCount();
        return $count;

    }

    function loginUser($username, $password){

        $query = $this->link->query("SELECT * FROM users WHERE username='$username' AND password='$password'");
        $rowCount = $query->rowCount();
        return $rowCount;

    }

    function getUserInfo($username){

        $query = $this->link->query("SELECT * FROM users WHERE username  = '$username'");
        $rowCount = $query->rowCount();

        if($rowCount == 1){

            $results = $query->fetchAll();
            return $results;

        }
        else{
            return $rowCount;
        }
    }
}

?>

J.Mlangeni
  • 35
  • 9

0 Answers0