Jump to content

undefined method mysqli::error()


argan328

Recommended Posts

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! :o

 

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;
       }
    }

} 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.