Welcome Guest, Not a member yet? Register   Sign In
Direct Query error using db_connect
#1

PHP Code:
public function load_data(){
        $page $this->request->getPost('pageno');
        $limit 20;
        $offset $limit * ($page 1);
        $search=$this->request->getPost('search');

        $where "1=1";

        if($search){
            $searchKey "roles.role like '%$search%' or departments.depart like '%$search%'";
            $where .=" AND ($searchKey)";
        }

        $sql "SELECT roles.id, role, depart from roles join departments on departments.id=roles.depart_id where $where order by id desc LIMIT $offset$limit";

        $totalQuery "SELECT count(*) as total_records from roles where $where";

        $totalRecords $this->db->query($totalQuery)->getRow()->total_records;
        $roles $this->db->query($sql)->getResultArray();
        
        $data 
= [
            'total_records' => $totalRecords,
            'roles' => $roles,
            'limit' => $limit,
        ];
        return $this->response->setJSON($data);
        
    
}

what is the error hereI am getting error "unknown column departments.depart" 
Reply
#2

Check the SQL statements you executed.

And your code has a SQL injection vulnerability.
You need to learn about SQL injections.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB