php mvc表单不起作用

时间:2014-05-14 05:32:44

标签: php forms codeigniter

我想更新下面的字段,但我的表单不起作用。它不存储数据应该怎么做。我在字段中使用了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>";
        }

&GT?;     

CONTROLLER

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);
}

MODEL

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;
}

1 个答案:

答案 0 :(得分:0)

您可以在模型中执行以下操作:

       $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