<< Error message >>
Severity: Notice
Message: Uninitialized string offset: 0
Filename: controllers
Line Number: 192
这是我遇到的错误消息。以下是控制器和模型文件。
// 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 '';
}
}
在模型文件中有一个getByEmail函数,它输出查询结果数组。但它会犯错误。我该怎么办?
提前致谢:)
答案 0 :(得分:3)
您指定了if($user = '')
至少它必须是
if($user == '')
答案 1 :(得分:1)
在代码中的某个地方,您尝试获取字符串的第一个字符,然后再将其测试为空 (或者你想使用它作为一个数组而不是它,但首先会发出警告)
$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'];