Validation with 2 condition when insert into table

hi all!

anyone can help me? i want to insert new data into my table, based on my table below.
i want validate condition before insert new record data. if kar_id and date_created already exist, user can’t insert new record data. this is my code

//Check if Duplicate Record Already Exit In The Database
			$db->where("kar_id", $modeldata['kar_id'])->where("date_created", $modeldata['date_created"']);
			if($db->has($tablename)){
				$this->view->page_error[] = $modeldata['kar_id']." Already exist!";
			} 
			if($this->validated()){
				$rec_id = $this->rec_id = $db->insert($tablename, $modeldata);
				if($rec_id){
					$this->set_flash_msg("Record added successfully", "success");
					return	$this->redirect("mst_pos");
				}
				else{
					$this->set_page_error();
				}
			}


up… please some help