cgm225 Posted April 27, 2008 Share Posted April 27, 2008 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(); Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 27, 2008 Share Posted April 27, 2008 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 = '?' "); Quote Link to comment Share on other sites More sharing options...
cgm225 Posted April 27, 2008 Author Share Posted April 27, 2008 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.