嘿伙计我在codeigniter中通过表单运行更新查询时遇到问题。没有返回错误,但查询未在数据库中更新。应该注意的是,在同一页面上运行插入查询的另一种形式可以正常工作。
查看:
<?php
$modify = array(
'id' => 'modify-form',
'class' => ''
);
echo form_open('main/modify_idea', $modify);
$ta_modify = array(
'id' => $row->id,
'name' => 'ta_modify',
'label' => 'ta_modify',
'placeholder' => $row->idea,
'method' => 'Post'
);
echo form_textarea($ta_modify);
echo form_hidden('facebook_id', $session['id']);
echo "<div id='button'>";
echo form_submit('submit', 'Post');
echo "</div>";
echo form_close();
?>
控制器:
public function modify_idea() {
$this->load->model('idea');
$this->idea->modify_idea();
redirect('main/members');
}
型号:
public function modify_idea() {
$data = array(
'id' => $this->input->post('id'),
'idea' => $this->input->post('ta_modify'),
'facebook_id' => $this->input->post('facebook_id')
);
$query = $this->db->query("UPDATE idea SET `idea` = ? WHERE `id` =?", array($data['idea'], $data['id']));
return $query;
}
我使用了以下资源,但仍然没有运气:
CodeIgniter MySQL query not working
CodeIgniter MySQL Query not returning any data, even though there definitely is data to be returned!
http://www.tutorialspoint.com/mysql/mysql-update-query.htm
http://ellislab.com/codeigniter/user-guide/database/active_record.html#delete
一如既往,感谢您的帮助!
答案 0 :(得分:0)
将您的帖子数据从控制器传递到模型
更改您的控制器代码:
public function modify_idea() {
$this->load->model('idea');
$data = array(
'id' => $this->input->post('id'),
'idea' => $this->input->post('ta_modify'),
'facebook_id' => $this->input->post('facebook_id')
);
$this->idea->modify_idea($data);
redirect('main/members');
}
模型中的执行此操作
public function modify_idea($data) {
$query = $this->db->query("UPDATE idea SET `idea` = ? WHERE `id` =?",
array($data['idea'], $data['id']));
return $query;
}
答案 1 :(得分:0)
请将您的帖子值传递给控制器的模型。然后它会工作。