嘿伙计们,我在通过 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 不返回任何数据,即使肯定有要返回的数据!
http://www.tutorialspoint.com/mysql/mysql-update-query.htm
https://www.codeigniter.com/userguide3/database/query_builder.html#deleting-data
一如既往,感谢您的帮助!