我创建了一个编辑页面,将他们的信息重新填充到正确的字段中(基于 ID),他们可以修改详细信息......
我现在想要的是提交按钮来更新数据库表中的这些信息?
这是我的控制器中的编辑部分:
function edit($id = 0){
$this->load->model('blogmodel');
if( $this->input->post() ){ #if form submitted
$data = array();
$id = $this->input->post('id'); #to be used in the where clause for updation
$data['name'] = $this->input->post('name');
$data['address'] = $this->input->post('address');
$data['sEmail'] = $this->input->post('sEmail');
$this->blogmodel->update_blog($data,$id);
}else{
// Form Validation required
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('address', 'Address', 'required');
$this->form_validation->set_rules('sEmail', 'Sender Email', 'required|valid_email');
$this->form_validation->set_message('required', '%s is required');
$this->form_validation->set_error_delimiters('<span class="error">', '</span><br />');
$sql = 'SELECT * FROM databse.blogs WHERE id = ?';
echo $sql . ' - '. $id;
$sql_params = array($id);
$query = $this->db->query($sql, $sql_params);
$form = $query->row_array();
//$date['form'] = $form;
$data['inputs'] = array('name' => $form['name'],
'address' => $form['address'],
'semail' => $form['email'],
'nickname' => $form
);
$data['Name']= $form['name'];
$data['Address']= $form['address'];
$data['Email']= $form['email'];
$this->load->view('blog_content',$data);
$data = $this->input->post();
$result = $this->blogmodel->update_blog($data,$id);
$this->load->view('blog_success');
}
}
}
到目前为止,这是我的模型:
function send_blog(&$data){
$data['name'] = $this->input->post('name');
$data['address'] = $this->input->post('address');
$data['sEmail'] = $this->input->post('sEmail');
$sql = "UPDATE database.blogs (name, address, email) WHERE id = $id
VALUES (".$this->db->escape($data['name']).",
".$this->db->escape($data['address']).",
'".$data['sEmail']."');";
$this->db->query($sql);
}
function update(&$data,$id){
$data['name'] = $this->input->post('name');
$data['address'] = $this->input->post('address');
$data['sEmail'] = $this->input->post('sEmail');
$this->db->where('id', $this->input->post('id'));
$this->db->update('blog', $data);
}
}