新人,数据库更新操作问题?
php初学者,刚接触CI没多久,跟着那个20分钟视频学习一下,加了一个添加,修改等动作。在添加修改文章的时候,出现了问题。控制器代码:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->scaffolding('entries');
}
function index()
{
$data['title'] = "我的博客标题";
$data['heading'] = "我的博客头部";
$this->db->orderby("id", "desc");
$data['query'] = $this->db->get('entries');
$this->load->view('welcome_message',$data);
}
function comments()
{
$data['title'] = "我的评论";
$data['heading'] = "查看评论";
$this->db->where('entry_id',$this->uri->segment(3));
$data['query'] = $this->db->get('comments');
$this->load->view('comment_view',$data);
}
function comments_insert()
{
$this->db->insert('comments',$_POST);
redirect('welcome/comments/'.$_POST['entry_id']);
}
function article()
{
$data['title'] = "我的日志";
$data['heading'] = "添加文章";
$this->load->view('article',$data);
}
function article_add()
{
$this->db->insert('entries',$_POST);
redirect('welcome');
}
function article_del()
{
$this->db->where('id',$this->uri->segment(3));
$this->db->delete('entries');
redirect('welcome');
}
function update()
{
$data['title'] = "我的文章";
$data['heading'] = "修改文章";
$this->db->where('id',$this->uri->segment(3));
$data['query'] = $this->db->get('entries');
$this->load->view('update',$data);
}
function{
$this->db->where('id',$this->uri->segment(3));
$this->db->update('entries',$_POST);
redirect('welcome');
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
?>
其它方法都可以,就是article_up()不能实现。。。。。把$this->uri->segment(3)换成ID数字又可以。。。但同样方法在删除操作里又可以。
不知道为什么?
刚学没多久,大家不要见笑
具体是报什么错误呢? 没有报错,数据库也没更新。。。。
我怀疑这个代码有问题
$this->uri->segment(3)
直接改成ID号:比如说7,然后他就成功。。。。 你的 URL 是什么样子的?第三段 URL 是什么内容? 最后一个方法function article_up()
{
$this->db->where('id',$this->uri->segment(3));
$this->db->update('entries',$_POST);
redirect('welcome');
}
view:
<?php $row = $query->row_array();?>
<p><?=anchor('welcome/','返回');?></p>
<?=form_open('welcome/article_up');?>
<p><textarea name="body" rows="10"><?=$row['body']?></textarea></p>
<p><input name="title" type="text" value="<?=$row['title']?>"></p>
<p><input type="submit" value="确定"></p>
修改后提交,没有改变 http://127.0.0.1/test/index.php/welcome/update/9 是文章自增ID号 看起来没什么问题呀,没报任何错误? 本帖最后由 lason 于 2009-12-11 15:31 编辑
function article_up()
{
$data=array(
'title'=>$_POST['title'],
'body'=>$_POST['body'],
);
$this->db->update('entries',$data,array('id' => $_POST['id']));
echo '成功';
}
改了一下,可以了,,,,,,
用这句不行,不知道为什么
$this->db->where('id',$this->uri->segment(3)); $this->db->update('entries',$data,array('id' => $_POST['id']));
update有第三个参数没想到,手册里没有提到
页:
[1]