[英]Re-entry of Data in database
I have this validation on my on-going system in which the scenario is like this: 我在正在进行的系统中对此场景进行了验证,如下所示:
If the employee is exist on designation 1 and branch 1 he/she could proceed to other designation 2 and branch 2 and so on. 如果该员工在名称1和分支1上存在,则他/她可以转到其他名称2和分支2,依此类推。 I have this code:
我有以下代码:
Here is on my view: 在我看来:
$emp_id = $this->input->post('emp_id');
$position =$this->input->post('d_id');
$branch =$this->input->post('b_id');
$date1 =$this->input->post('datepicker');
$date2=$this->input->post('datepicker2');
This is on my Controller: 这是在我的控制器上:
$sql_test = $this->db->select("employee_id, designation_id,branch_id")->from("tb_emp_record2")->where("employee_id", $emp_id)->get();
foreach($sql_test->result() as $val){
$validate_employee = $val->employee_id;
$validate_position = $val->designation_id;
$validate_branch = $val->branch_id;
}
and here's my validation code sample: 这是我的验证代码示例:
if($validate_employee === $emp_id && $validate_position === $position && $validate_branch === $branch){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error1');
//$this->load->view('evaluation');
}elseif($validate_employee === $position && $validate_employee === $branch){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error2');
}elseif($position === $validate_employee && $validate_position === $emp_id){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error3');
}elseif($position === $validate_position && $emp_id === $validate_employee){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error4');
}elseif($branch === $validate_branch && $emp_id === $validate_employee){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error5');
}elseif($validate_employee === $date1 && $validate_employee === $date2){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error6');
}else{
$this->db->insert('tb_emp_record2', $insert_eval);
redirect('Mainx/evaluation_form/' .$emp_id. '/success' );
}
At first it was working after an success attempt as I go on to check for an error it insert an invalid entry. 刚开始尝试成功后,它一直在工作,因为我继续检查错误,因此插入了无效的条目。
Hey guys I finally answered my question. 大家好,我终于回答了我的问题。 Yes, I am very happy and here's my working code:
是的,我很高兴,这是我的工作代码:
$employee_id = array();
$designation_id = array();
$branch_id = array();
$date_start = array();
$date_end = array();
//$sql_test = $this->db->select("emp_record_id,employee_id, designation_id,branch_id,date_start,date_end")->from("tb_emp_record2")->where("employee_id", $emp_id)->get();
$this->db->select("*");
$this->db->from("tb_emp_record2");
$this->db->join("tb_designation", "tb_emp_record2.designation_id = tb_designation.designation_id", "inner");
$this->db->join("tb_branch", "tb_emp_record2.branch_id = tb_branch.branch_id", "inner");
$this->db->where("employee_id", $emp_id );
$sql_test = $this->db->get();
foreach($sql_test->result() as $val){
$employee_id[] = $val->employee_id;
$designation_id[] = $val->designation_id;
$branch_id[] = $val->branch_id;
$date_start[] = $val->date_start;
$date_end[] = $val->date_end;
}
if(in_array($position, $designation_id) && in_array($branch, $branch_id) && in_array($date1, $date_start) && in_array($date2, $date_end)){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error1');
}
else {
$this->db->insert('tb_emp_record2', $insert_eval);
redirect('Mainx/evaluation_form/' .$emp_id. '/success' );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.