dtddjq9637 2016-02-19 03:57
浏览 23
已采纳

在数据库中重新输入数据

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. 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.

  • 写回答

1条回答 默认 最新

  • doubaben7394 2016-02-23 03:29
    关注

    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' );
                    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求