【问题标题】:php mvc form not workingphp mvc表单不起作用
【发布时间】:2014-05-14 05:32:44
【问题描述】:

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

【问题讨论】:

  • 所以为每个字段创建一个表单?
  • 是的,它是如何工作的

标签: php forms codeigniter


【解决方案1】:

你可以在你的模型中做这样的事情:

       $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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 2014-02-24
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多