I am trying to write a class that will allow me to add a member to my users database change tehir password log them in and out, i am using the PEAR DB class to connect to my database, i am getting this error when i run the script, i am trying to login:
Fatal error: Call to a member function on a non-object in /home/nanothre/public_html/classes/member.class.php on line 22
My member class is here:(I have put a comment next to line 22)
PHP Code:
class member {
var $db;
var $databaseTable;
var $username;
var $password;
var $result;
function login($username, $password){
if(!get_magic_quotes_gpc()){
$password = addslashes($password);
$username = addslashes($username);
}
$password = md5($password);
$sql = "SELECT id, username, password FROM $databaseTable WHERE username = '$username' AND password = '$password'";
$this->result = $db->query($sql); //<<<<<<<<<<<<<<<<LINE 22
if (DB::isError ($result)){
die('There was an error while processing the query: '. $result->getMessage());
}
if($result->numRows() > 0){
$row = $result->fetchrow(DB_FETCHMODE_ASSOC);
$_SESSION['id'] = $row['id'];
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
print_r($_SESSION);
} else {
return false;
}
$result->free();
}
function logout(){
session_destroy();
}
function newMember($password, $username, $email){
if(!get_magic_quotes_gpc()){
$password = addslashes($password);
$username = addslashes($username);
$email = addslashes($email);
}
$sql = "INSERT INTO $databaseTable(username, email, password) VALUES('$username','$email','$password')";
$result = $db->query($sql);
if (DB::isError ($result)){
die('There was an error while processing the query: '. $result->getMessage());
}
}
}
After the username and password have been submitted this is what is called by the script:
PHP Code:
$member = new member;
$member->databaseTable = 'test_users';
$member->db = $db;
$member->login($_POST['username'], $_POST['password']);
Can anyone explain what is wrong?
|