您好我是codeigniter的新手我已经编写了更新一个表数据的代码以正确的方式进行,但它没有在数据库表中更新,它是fire insert查询而不是更新。
这是我的控制器方法客户端是表
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");
}
}
答案 0 :(得分:0)
我发现数据库中的表存在问题。我没有将主键设置为id,这就是为什么它不更新需要为要使用数据映射器更新表中任何记录的字段设置主键。
感谢大家的评论。