简体   繁体   中英

Save() is not updating data in table in datamapper with codeigniter

Hi I am new to codeigniter i have written code to update one table data goes in right manner but it's not updating in database table and it's fire insert query instead of update .

here is my controller method Clients is table

public function editClients($id="")
        {
            Auth::RequireFleetindia();
            $this->template->set("fleet_india");
            $this->template->setData("SelectedTab", "Clients");

            $this->Clientsedit = new Clients();
            $this->Clientsedit->where(array("account_id"=> Auth::get("id"),'ID'=>$id))->get();

            if(isset($_POST['Submit']))
            {   echo $this->Clientsedit->ID;
                $this->load->library('form_validation');
                $this->form_validation->set_rules('clientname', 'Client Name', 'required');
                $this->form_validation->set_rules('address', 'Address', 'required');
                $is_unique='';
                if($this->input->post('clientemail') != $this->Clientsedit->email) 
                {
                       $is_unique =  '|is_unique[clients.email]';

                } 
                $this->form_validation->set_rules('clientemail', 'Client Email', 'required|valid_email'.$is_unique);

                $this->form_validation->set_rules('daily_rate', 'Daily Rate', 'numeric');
                $this->form_validation->set_rules('daily_contract_mileage', 'Daily Contract Mileage', 'numeric');
                $this->form_validation->set_rules('excess_mileage_rate', 'Excess Mileage Rate', 'numeric');
                $this->form_validation->set_rules('daily_contract_time', 'Daily Contract Time', 'numeric');
                $this->form_validation->set_rules('overtime_rate', 'Overtime_Rate', 'numeric');
                $this->form_validation->set_rules('night_shift_rate', 'Night Shift Rate', 'numeric');
                $this->form_validation->set_rules('overtime_incentives', 'Overtime Incentives', 'numeric');
                $this->form_validation->set_rules('taxrate1', 'Tax Rate', 'numeric');
                $this->form_validation->set_rules('taxrate2', 'Tax Rate', 'numeric');



                if($this->form_validation->run() != FALSE)
                {
                    $this->Clientsedit->client_name             =   $this->input->post('clientname');
                    $this->Clientsedit->address                 =   $this->input->post('address');
                    $this->Clientsedit->email                   =   $this->input->post('clientemail');
                    $this->Clientsedit->daily_rate              =   $this->input->post('daily_rate');
                    $this->Clientsedit->daily_contract_mileage  =   $this->input->post('daily_contract_mileage');
                    $this->Clientsedit->excess_mileage_rate     =   $this->input->post('excess_mileage_rate');
                    $this->Clientsedit->daily_contract_time     =   $this->input->post('daily_contract_time');
                    $this->Clientsedit->overtime_rate           =   $this->input->post('overtime_rate');
                    $this->Clientsedit->night_shift_rate        =   $this->input->post('night_shift_rate');
                    $this->Clientsedit->overtime_incentives     =   $this->input->post('overtime_incentives');
                    $this->Clientsedit->taxrate1                =   $this->input->post('taxrate1');
                    $this->Clientsedit->taxrate2                =   $this->input->post('taxrate2');


                    if($this->Clientsedit->save())
                    {
                        echo '<pre>';
                        print_r($this->Clientsedit);
                        echo '</pre>';
                        $this->session->set_flashdata('msg', 'Client Updated');
                        //redirect("fleet_india_client/editClients","refresh");
                    }
                    else
                    {
                        $error = $this->Clientsedit->error->string;
                        echo $error;
                        echo $this->Clientsedit->address ;
                        //redirect("fleet_india_client/editClients","refresh");
                    }

                }
                else
                {
                    //$this->load->view("fleet_india/clients/editClients");
                }
            }
            else
            {
                $this->load->view("fleet_india/clients/editClients");
            }
        }  

I found the mistake there was problem with my table in database. i have not set primary key to id , that's why it's not updating need to set primary key for the field by which you want to update any record in table using data mapper.

Thanks to everyone for commenting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM