简体   繁体   中英

Uninitialized string offset: 0, why?

<< Error message >>
Severity: Notice
Message: Uninitialized string offset: 0
Filename: controllers
Line Number: 192

This is the error message i encountered. and below are the controller and model files.

// controller file
    $user = $this->user_model->getByMail(array('total_mail' => $mail_auth));

    if($user = '') 
    {
        $this->load->helper('url');
        redirect('/');
    }
    else if($this->encrypt->decode($user['password']) == $password_auth) // line 192
    {
        if($user['verified'] == 'N')
        {
            $this->session->set_flashdata('message', 'Wront inputs.');
            $this->load->helper('url');
            redirect('/');
        }
    }
    else
    {
        $this->session->set_flashdata('message', 'Wrong inputs');
        $this->load->helper('url');
        redirect('/');
    }

}
    // model file
function getByMail($option)
{
    $basic_result = $this->db->get_where('ndd_user', array('total_mail' => sanitizeMySQL($option['total_mail'])));
    if ( $basic_result->num_rows() > 0 )
    {
        $result = $basic_result->row_array();
        return $result;
    }
    else
    {
        return '';
    }
}

In the model file there is a getByEmail function which outputs the array of query results. However It makes error. How can I do?

Thanks in advance :)

You assigning if($user = '')

at least it must be

if($user == '') 

Somewhere in your code you try to get some string's first character before testing it's empty (or you want to use as an array while it's not, but that throws a warning first)

$foo = '';

// these throws "Notice: Uninitialized string offset: 0"
$firstChar = $foo[0];
$firstChar = $foo{0};

// this throws "Warning: Illegal string offset 'bar'"
// and "Notice: Uninitialized string offset: 0"
$bar = $foo['bar'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM