php - 意外的 T_STRING,期待 T_FUNCTION

标签 php mysql codeigniter

<分区>

刚刚学习如何使用 PHP 和 MySQL,使用 CodeIgniter。遇到那个错误。

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

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;
        }
}

使用正确的凭据登录没有问题。输入不正确的密码时,会遇到该错误。非常感谢任何帮助。

最佳答案

你有一个语法错误:

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

应该是:

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

您忘记了 {

关于php - 意外的 T_STRING,期待 T_FUNCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10704705/

相关文章:

php - 无法发送应用程序请求,显然已发送但未出现通知用户

oracle - 我可以使用 PHP7 提高 oci8 的性能吗?

PHP 片段问题

php - 复杂对象上的 mysql_fetch_object

MYSQL 根据秤 ID 从同一表返回值

php - MYSQL 重复条目上的 AJAX 响应

javascript - 我在 ajax 成功中收到我的数据如何在表中显示 jquery 数据

php - 转移到新服务器,现在 CodeIgniter/Ion_Auth 无法工作

php - 插入查询不做任何事情

php - 如何修改 SQL 来加快速度?