argan328 Posted March 4, 2007 Share Posted March 4, 2007 Hi, cannot figure out why I am getting this error: Fatal error: Call to undefined method mysqli::error() in /home/content/x/x/x/xxxxx/html/user_login/Account.class on line 122 This is a user login script, part of a package of five classes and a few other files in total. Not sure if the error is actually in another file but posted the whole account.class. I still consider myself a newbie and am sure this is an easy problem to solve since it's just a matter of tracking the error back to its source, only problem is I can't figure it out myself! Any help would be MUCH appreciated! <?php /* Class: Account * Desc: A user account stored in a database. Represents * the account information stored in one record * in a table. */ class Account { private $userID = NULL; private $cxn; private $table_name; private $message; function __construct( mysqli $cxn,$table) { $this->cxn = $cxn; if(is_string($table)) #17 { $sql = "SHOW TABLES LIKE '$table'"; #19 $result = $this->cxn->query($sql); if($result->num_rows > 0) #21 { $this->table_name = $table; } else #25 { throw new Exception("$table is not a table in the database"); return FALSE; } } else #32 { throw new Exception("Second parameter is not a valid table name"); return FALSE; } } function selectAccount($userID) { $userID = trim($userID); #42 $sql = "SELECT user_name FROM $this->table_name WHERE user_name ='$userID'"; #44 if(!$result = $this->cxn->query($sql)) { throw new Exception("Couldn't execute query: " .$this->cxn->error()); return FALSE; } if($result->num_rows < 1 ) #51 { $this->message = "Account $userID does not exist!"; return FALSE; } else #57 { $this->userID = $userID; return TRUE; } } function comparePassword($form_password) { if(!isset($this->userID)) #66 { throw new Exception("No account currently selected"); exit(); } #70 $sql = "SELECT user_name FROM $this->table_name WHERE user_name ='$this->userID' AND password = md5('$form_password')"; if(!$result = $this->cxn->query($sql)) #74 { throw new Exception("Couldn't execute query: " .$this->cxn->error()); exit(); } if($result->num_rows < 1 ) #80 { $this->message = "Incorrect password for account $this->userID!"; return FALSE; } else #86 return TRUE; } function getMessage() { return $this->message; } function createNewAccount($data) { if(!is_array($data)) #97 { throw new Exception("Data must be in an array."); return FALSE; } foreach($data as $field => $value) #102 { if($field != "password" and $field != "Button") { $fields[] = $field; $values[] = addslashes($value); } } $str_fields = implode($fields,","); #110 $str_values = '"'.implode($values,'","'); #111 $today = date("Y-m-d"); #112 $str_fields .=",create_date"; $str_fields .=",password"; $str_values .="\",\"$today"; $str_values .="\",md5(\"{$data['password']}\")"; $sql = "INSERT INTO $this->table_name ($str_fields) VALUES ($str_values)"; if(!$this->cxn->query($sql)) #119 { throw new Exception("Can't execute query: " .$this->cxn->error()); return FALSE; } else { return TRUE; } } } ?> Quote Link to comment Share on other sites More sharing options...
argan328 Posted March 4, 2007 Author Share Posted March 4, 2007 I've tried commenting out that if statement but then I just get another error message... can anyone help please?? Quote Link to comment Share on other sites More sharing options...
trq Posted March 4, 2007 Share Posted March 4, 2007 error is a property of mysqli, not a function. You'll need to make your calls without the (). eg; $this->cxn->error(); becomes.... $this->cxn->error; Quote Link to comment Share on other sites More sharing options...
argan328 Posted March 4, 2007 Author Share Posted March 4, 2007 wow that did it! Thank you... it worked but I don't understand why. Can you (or anyone?) tell me what you meant by "error is a property of mysqli, not a function"?? 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.