Yasitha
Yasitha

Reputation: 911

error in codeigniter custom where clause

I'm referring the codeigniter user guide to write a custom where clause. as per the guide it says for custom where clauses write like this.

 $where = "name='Joe' AND status='boss' OR status='active'";
 $this->db->where($where); 

but when i use in my model browser is throwing an error.

A Database Error Occurred

Error Number: 1054

Unknown column 'user_name='Joe'' in 'where clause'

SELECT * FROM (`Management`) WHERE `user_name='Joe'` AND password='boss' OR password='active'

Filename: /var/www/models/hr_login_model.php

Line Number: 28

this is just a testing query. my actual query is dynamic one and it is also giving this error.

$where = "user_name='".$username."' AND password='".$password."' AND Department='".$dep_br."' OR Br_no='".$dep_br."'";

why it always taking the column name and the value, both as a column name?

Upvotes: 2

Views: 2498

Answers (4)

MJ X
MJ X

Reputation: 9054

Try this way it is much more better and secure

$this->db->where("name","joe");
$this->db->where("status =","boss");
$this->db->or_where("status","active");

Upvotes: 1

user2936213
user2936213

Reputation: 1011

Try this:

$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where, NULL, FALSE);

Upvotes: 1

Manish Jangir
Manish Jangir

Reputation: 5437

use following

$where = "user_name='$username' AND password='$password' AND (Department='$dep_br' OR Br_no='$dep_br')";

Upvotes: 0

User space befor and after = like shown below.

$where = "name = 'Joe' AND status = 'boss' OR status = 'active'"; 
$this->db->where($where); 

Upvotes: 3

Related Questions