Welcome Guest, Not a member yet? Register   Sign In
Can not Update Data
#1

Hello Everyone !

i am working on Codeigniter...
im trying to do simple thing ! i have a form in which there is different section..actually it looks there is 5 form in one page but i have taken only one form with one submit button..

not what the issue is,if i m going to fill up the second form then third form's data is deleted in DB While second Form's data can inserted but another form's data is deleted

here is my Code of Controller

PHP Code:
$Resume $this->input->post();        $ResumeInsert=array();
$ResumeUpdate=array();

foreach(
$this->input->post('Person_id') as $key =>$value ){
$ResumeInsert[$key]['updated'] = Date("Y-m-d");
                    
$ResumeInsert[$key]['Importance_JK'] = $Resume['Importance_JK'];
                    
$ResumeInsert[$key]['user_FK'] = $user_id;
                    
$ResumeInsert[$key]['Person_id'] = $Resume['Person_id'][$key];
                    
$ResumeInsert[$key]['email_contact'] = $Resume['email_contact'][$key];
                    
$ResumeInsert[$key]['Contact_Phone'] = $Resume['Contact_Phone'][$key];
                    
$ResumeInsert[$key]['communication'] = $Resume['communication'][$key];
                    
$ResumeInsert[$key]['creativity'] = $Resume['creativity'][$key];
                    
$ResumeInsert[$key]['team_work'] = $Resume['team_work'][$key];
                    
$ResumeInsert[$key]['organizational'] = $Resume['organizational'][$key];
                    
$ResumeInsert[$key]['Leadership'] = $Resume['Leadership'][$key];
                    
$ResumeInsert[$key]['Productivity'] = $Resume['Productivity'][$key];
                    
$ResumeInsert[$key]['Postal_Address'] = $Resume['Postal_Address'][$key];
                    
$ResumeInsert[$key]['Career_objective'] = $Resume['Career_objective'][$key];
if(isset(
$Resume['id'][$key])){
                        
//echo "update";
                        //echo $Resume['id'][$key];exit;
                        
$Key_Resume__ExistIDs[]=$Resume['id'][$key];
                        
$ResumeUpdate[$key]=$ResumeInsert[$key];
                        
//print_r ($ResumeUpdate[$key]);exit;
                        
$ResumeUpdate[$key]['resume_id']=$Resume['id'][$key];
                        unset(
$ResumeInsert[$key]);
                    }
                     else{
                        
//echo "inset";exit;
                        
$ResumeInsert[$key]['resume_id'] = $GetLastID;
                        
$GetLastID++;
                    }
                }
foreach(
$this->input->post('resume_id') as $key =>$value ){
$ResumeInsert[$key]['resume_keyid'] = $Resume['resume_id'][$key];
                    
$ResumeInsert[$key]['employer_name'] = $Resume['employer_name'][$key];
                    
$ResumeInsert[$key]['start_Date'] = $Resume['start_Date'][$key];
                    
$ResumeInsert[$key]['end_date'] = $Resume['end_date'][$key];
                    
$ResumeInsert[$key]['type_id'] = $Resume['type_id'][$key];
                    
$ResumeInsert[$key]['position'] = $Resume['position'][$key];
                    
$ResumeInsert[$key]['responsibility'] = $Resume['responsibility'][$key];
                    
$ResumeInsert[$key]['Skills'] = $Resume['Skills'][$key];
                    
//print_r($ResumeInsert);exit;
                    
                    //print_r($Resume['employer_name'][$key]);exit;
                    
                    
if(isset($Resume['id'][$key]) ){
                        
//echo "update";
                        
$Key_Resume__ExistIDs[]=$Resume['id'][$key];
                        
$ResumeUpdate[$key]=$ResumeInsert[$key];
                        
$ResumeUpdate[$key]['resume_id']=$Resume['id'][$key];
                        unset(
$ResumeInsert[$key]);
                    }
                     else{
                        
//echo "insert";exit;
                         
$ResumeInsert[$key]['resume_id'] = $GetLastID;
                        
// print_r ($ResumeInsert[$key]);exit;
                         
$GetLastID++;
                    } 
                }
foreach(
$this->input->post('resume_id1') as $key =>$value ){
                    
//echo "eee";exit;
                 
   /*---------Start Docs Upload---------*/
                    
 
                       /*---------END Docs Upload---------*/
                    
$Resume $this->input->post();
                    
                    
$ResumeInsert[$key]['edu_id'] = $Resume['resume_id1'][$key];
                    
$ResumeInsert[$key]['year_gain'] = $Resume['year_gain'][$key];
                    
$ResumeInsert[$key]['qualification_name'] = $Resume['qualification_name'][$key];
                    
$ResumeInsert[$key]['institution_name'] = $Resume['institution_name'][$key];
                    
$ResumeInsert[$key]['outstanding_Ach'] = $Resume['outstanding_Ach'][$key];
                    
$ResumeInsert[$key]['aquired_skill'] = $Resume['aquired_skill'][$key];
                    
$ResumeInsert[$key]['expiry'] = $Resume['expiry'][$key];
                    
$ResumeInsert[$key]['Application_of_Skill'] = $Resume['Application_of_Skill'][$key];
                    
//print_r($ResumeInsert);exit;
                    
                    //print_r($Resume['employer_name'][$key]);exit;
                    
                    
if(isset($Resume['id'][$key])){
                        
                        
$Key_Resume__ExistIDs[]=$Resume['id'][$key];
                        
$ResumeUpdate[$key]=$ResumeInsert[$key];
                        
$ResumeUpdate[$key]['resume_id']=$Resume['id'][$key];
                        unset(
$ResumeInsert[$key]);
                    }
                     else{
                        
                        
$ResumeInsert[$key]['resume_id'] = $GetLastID;
                        
$GetLastID++;
                    } 
                }
$idsToDelete='';
                if(empty(
$ResumeInsert) &&  empty($ResumeUpdate)){
                    
//echo "delete query";exit;
                    
$idsToDelete=array_diff($Key_Resume_IDs,$Key_Resume__ExistIDs);
                }
                
$status=$this->Resume_model->ProcessData($idsToDelete,$ResumeUpdate,$user_id,$ResumeInsert,$imgInsert,$imgUpdate);
                    
         
       redirect('Resume','refresh'); 


here is my Model

PHP Code:
function ProcessData($idsToDelete,$tbl_resumeUpdate,$user_id,$tbl_resumeInsert,$imgInsert,$imgUpdate){
        
$this->db->trans_start();
        if(!empty(
$idsToDelete)){
            
$this->delete_tbl_resume($idsToDelete);
        }
        if(!empty(
$tbl_resumeUpdate)){
            
//echo "up";exit;
            
$this->update_tbl_resume($tbl_resumeUpdate);
        }
        if(!empty(
$tbl_resumeInsert)){
            
//echo "int";exit;
            
$this->insert_tbl_resume($user_id,$tbl_resumeInsert);
        }
        if(!empty(
$imgInsert)){
            
$this->insert_tbl_file_paths($imgInsert);
        }
        if(!empty(
$imgUpdate)){
            
$this->update_tbl_file_paths($imgUpdate);
        }
        return 
$this->db->trans_complete();
    }
function 
insert_tbl_resume($id,$arrtbl_resume){
        
//$a = $this->db->insert_batch('tbl_resume', $arrtbl_resume); 
        //echo $this->db->last_query();exit;
        
$this->db->insert_batch('tbl_resume'$arrtbl_resume); 
        
    }
    function 
update_tbl_resume($arrtbl_resume){
        
         
$this->db->update_batch('tbl_resume'$arrtbl_resume'resume_id');
         
//$a = $this->db->update_batch('tbl_resume', $arrtbl_resume, 'resume_id');
         //echo $this->db->last_query();exit;
         //print_r ($arrtbl_resume);exit;
    



im very Confuse About This code ! last form's data deleted when im going to insert/update any form

please any help?
Reply
#2

i don't know if anyone on the forum is going to try and tackle this, but this is not a "simple thing". my suggestion would be to start over with something much simpler - like two fields. get that working. then add the rest of the fields. also suggest that you refactor your ProcessData method in your model - its doing way too much. the more responsibilities a method has, the more difficult it is to debug.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB