我需要在我的sql中更改一个字符串,脚本可以正常工作,但什么都不做。我正在尝试输入ID我要更改哪一行,然后输入条件如何更改该行变量。这是我的代码。
控制器:
public function admin(){
$this->load->model('model_users');
$data2['users'] = $this->model_users->change_condition();
$this->load->view("content_admin", $data2);
}
型号:
public function change_condition() {
$data = array(
'order_condition' => $this->input->post('order_condition')
);
$where = array(
'ID' => $this->input->post('ID')
);
$str = $this->db->update_string('users', $data, $where);
}
查看:
<form name="contactform" method="POST" action="<?php echo base_url();?>site/change">
<td valign="top">
ID
</td>
<input type="text" name="ID" maxlength="20" size="30">
<td valign="top">
Order Condition
</td>
<input type="text" name="order_condition" maxlength="80" size="30">
<input type="submit" value="Change" name="submit" />
</form>
答案 0 :(得分:0)
您应该使用$this->db->update()
代替$this->db->update_string
并在$where
中传递$this->db->where()
数组。 Example:
public function change_condition() {
$data = array(
'email' => $this->input->post('email')
);
$where = array(
'ID' => $this->input->post('ID')
);
$this->db->where($where);
$str = $this->db->update('users', $data);
return $str;
}