未初始化的字符串偏移量:0,为什么?

未初始化的字符串偏移量:0,为什么?

问题描述:

<< 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 :)

 &lt;&lt; 错误消息&gt;&gt; 
Severity:Notice 
Message:未初始化的字符串偏移量:0 
文件名:controllers 
号码:192 
  code>  pre> 
 
 

这是错误消息i 遇到。 以下是控制器和模型文件。 p>

  // controller file 
 $ user = $ this-&gt; user_model-&gt; getByMail(array('total_mail'=&gt;  ; $ mail_auth)); 
 
 if if($ user ='')
 {
 $ this-&gt; load-&gt; helper('url'); 
 redirect('/'); 
  } 
否则if($ this-&gt; encrypt-&gt; decode($ user ['password'])== $ password_auth)//第192行
 {
 if($ user ['verified'] ==  'N')
 {
 $ this-&gt; session-&gt; set_flashdata('message','Wront inputs。'); 
 $ this-&gt; load-&gt; helper('url'); \  n重定向('/'); 
} 
} 
其他
 {
 $ this-&gt; session-&gt; set_flashdata('message','错误的输入'); 
 $ this-&gt;  load-&gt; helper('url'); 
 redirect('/'); 
} 
 
} 
 //模型文件
函数getByMail($ option)
 {
 $ basic_result = $  this-&gt; db-&gt; get_where('ndd_user',array('total_mail'=&gt; sanitizeMySQL($ option ['total_mail']))); 
 if($ basic_result-&gt; num_rows()&gt; 0  )
 {
  $ result = $ basic_result-&gt; row_array(); 
返回$ result; 
} 
 else 
 {
 return''; 
} 
} 
  code>  pre> \  n 
 

在模型文件中有一个getByEmail函数,它输出查询结果数组。 但它会犯错误。 我该怎么办? p>

提前致谢:) p> div>

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'];