我想更新下面的字段,但我的表单不工作。我应该做的不是存储数据。我使用jquery手风琴为字段,所以它会点击他想要编辑的项目,然后更新字段,然后提交。
视图 foreach($people as $row){
echo "<h3>".$row->service."</h3>";
echo "<form action='".base_url()."some_controller/updateCI' method='post'> <div>Service ID: <input type=text name=id value='".$row->id."' size=27px/><br>Service Name: <input type=text name=name value='".$row->service."'><input type='button' class='classname' value='Save'/></form></div>";
}
?>
控制器public function updateCI(){
$this->load->model('some_model');
$id = $this->input->post('id');
$servName = $this->input->post('name');
$success = $this->some_model->updateCI($id,$servName);
if($success == TRUE)
$this->editCI_page(TRUE);
else $this->editCI_page(FALSE);
}
模型public function updateCI($id,$servName){
//$name = $this->db->escape_str($name);
$appID = $this->db->escape_str($id);
$ciName = $this->db->escape_str($servName);
$queryStr = "UPDATE appwarehouse.service SET id='$appID',service='$ciName' WHERE id = '$appID';";
$query = $this->db->query($queryStr);
return $query;
}
您可以在您的模型中这样做:
$data = array(
'title' => $title,
'name' => $name,
'date' => $date
);
$this->db->where('id', $id);
$this->db->update('mytable', $data);
我建议您使用可用于codeigniter的活动记录。更多信息请访问以下链接:
http://ellislab.com/codeigniter/user-guide/database/active_record.html