Jump to content

[SOLVED] Problem with MySQLi binding: call to member function bind_param() on non-object


cgm225

Recommended Posts

I have the following class and when I use it I get the following error: "Fatal error: Call to a member function bind_param() on a non-object in C:\public_html\DEVELOPMENT\authentication.php5 on line 26"

 

Is this a problem with my MySQLi binding?

 

Thanks in advance!  Any other feedback is greatly appreciated!

 

$mysqli = new mysqli(MYSQL_SERVER,MYSQL_SERVER_USERNAME,MYSQL_SERVER_PASSWORD);


class Authentication {
    
    //Declaring variables
    private $username;
    private $password;
    private $connection;

    //Setting username and password
    public function __construct($username, $password) {
        $this->username = $username;
        $this->password = md5($password);
    } 

    public function doLogin($connection, $database, $table, $usernameField, $passwordField) {
        $connection->select_db($database);
        $statement = $connection->prepare("SELECT COUNT(*) FROM '$table' WHERE '$usernameField' = ? AND '$passwordField' = ?");
        $statement->bind_param('ss', $this->username, $this->password);
        $statement->execute();
        $statement->bind_result($count);
        $statement->fetch();
        if ($count == 1) {
            $this->setSession($this->username, $this->password);
            return TRUE;
        } else {
            return FALSE;
        }
    }
    
    //Setting the provided username and password to session variables
    public function setSession($username, $password) {
        $_SESSION['username'] = $username;
        $_SESSION['password'] = $password;
    }
}


$authentication = new Authentication("user1", "pass1");
$authentication->doLogin($mysqli, '_authentication', 'users', 'username', 'password');

$mysqli->close();

i think  the problems with the prepare, try this

update

       $statement = $connection->prepare("SELECT COUNT(*) FROM '$table' WHERE '$usernameField' = ? AND '$passwordField' = ?");

to

       $statement = $connection->prepare("SELECT COUNT(*) FROM '$table' WHERE $usernameField = '?' AND $passwordField = '?' ");

 

close.. thanks for getting me on the right track

 

it needed to be

 

 

        $statement = $connection->prepare("SELECT COUNT(*) FROM $table WHERE $usernameField = ? AND $passwordField = ? ");
        $statement->bind_param('ss', $this->username, $this->password);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.