0

Code returns:

Notice: Undefined offset: 0  line 60
Notice: Undefined offset: 1  line 61
Notice: Undefined offset: 2  line 62

I don't know where is a mistake. I have no idea, so I need some help.

Part of code is below:

    private function action($action, $table, $where = array()) {
        if(count($where) === 3) {
            $operators = array('=','>','<','>=' ,'<=');


            $field      = $where[0]; //-----> LINE 60
            $operator   = $where[1]; //-----> LINE 61
            $value      = $where[2]; //-----> LINE 62

            if(in_array($operator, $operators)) {
            $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";

                if(!$this->query($sql, array($value))->error()) {
                    return $this;

                }

            }
        }
        return false;
    }
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
  • Any reason you're declaring an array like that? You can just use `$operators = ['=', '>', '<', '>=', '<='];` and what are you passing as `$where`? You don't need to strictly declare that it's an array either, though not sure on common practices there (I just ensure to never send a **not** array through to the function) – Zach Handley Jun 20 '18 at 21:18
  • 1
    output of `var_dump($where);`? – Sebastian Brosch Jun 20 '18 at 21:23
  • @SebastianBroschyou gave me a hint. I got mistake in index.php $user = DB::getInstance()->insert('users', array( 'username' => 'Dale', 'password' => 'password', 'salt' => 'salt' )); I wrote $user = DB::getInstance()->get('users', array(... Tnx, man. – SymfonyBeginner Jun 20 '18 at 21:45
  • We would need to see how you are calling this function i.e. what is in the `$where` variable. We have to assume NOTHING – RiggsFolly Jun 20 '18 at 23:09

0 Answers0