dongran1779 2017-02-15 08:53
浏览 15

登录模型出错

I am trying to create login. But on checking the credentials from database it is logging if any1 data is correct and other is incorrect also.
for login- name, email, mobile all are allowed.
'status' should be 'active' is an extra condition.
What am I doing wrong??

function login($username, $password) {
    $where = "status='active' AND name='$username' OR email_id= '$username' OR mobile_no='$username' AND password ='trim($password)'";
    $this->db->select('*');
    $this->db->from('user_details');
    $this->db->where($where);
    //$this->db->where('password', trim($password));
    $this->db->limit(1);

    $query = $this->db->get();
    if ($query->num_rows() == 1) {
        return $query->result();
    } else {
        return false;
    }
}
  • 写回答

2条回答 默认 最新

  • douluo7366 2017-02-15 08:56
    关注

    You have issue in where clause. You need to use parenthesis to check the columns with OR.

    Please check below.

     $where = "status='active' AND
          (name='$username' OR email_id= '$username' OR mobile_no='$username')
           AND password ='trim($password)'";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化