0

刚刚学习如何使用 CodeIgniter 使用 php 和 mysql。遇到那个错误。

我试图检查我的数据库的登录尝试,它们存储在哪里。以下是我的登录模型中的相关功能:

public function verify_user($email, $password)
    {
        $q = $this
        ->db
        ->where('email_address', $email)
        ->where('password', $password)
        ->limit(1)
        ->get('users');

            if ($q->num_rows > 0)
                return $q->row();
            }
            add_login_attempt($email);
            return false;
        }

        public function add_login_attempt($email)
        {
            $current_attempts = get_login_attempts($email);

            if ($current_attempts > 2)
            {
                lock_account($email);
            }
            else
            {
                $updated_attempts = $current_attempts + 1;
                $data = array('login_attempts' => $updated_attempts);
                $this->db->where('email_address', $email);
                $this->db->update('crm', $data);
            }

        }

        function reset_login_attempts($email)
        {

        }

        function lock_account($email)
        {

        }

        public function get_login_attempts($email)
        {
            $this->db->select('login_attempts');
            $this->db->from('crm');
            $this->db->where('email_address', $email);
            $login_attempts = $this->db->get();

            return $login_attempts;
        }
}

使用正确的凭据登录没有问题。当输入错误的密码时,会遇到该错误。任何帮助是极大的赞赏。

4

1 回答 1

8

你有一个语法错误:

if ($q->num_rows > 0)
    return $q->row();
}

应该:

if ($q->num_rows > 0) {
    return $q->row();
}

你忘了{

于 2012-05-22T15:05:02.210 回答