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(); Link to comment https://forums.phpfreaks.com/topic/103087-solved-problem-with-mysqli-binding-call-to-member-function-bind_param-on-non-object/ 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 = '?' "); Link to comment https://forums.phpfreaks.com/topic/103087-solved-problem-with-mysqli-binding-call-to-member-function-bind_param-on-non-object/#findComment-528048 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); Link to comment https://forums.phpfreaks.com/topic/103087-solved-problem-with-mysqli-binding-call-to-member-function-bind_param-on-non-object/#findComment-528053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.