【发布时间】:2015-06-25 03:51:45
【问题描述】:
我想使用活动记录更新我的数据库,但是我在 $data 数组中设置的计数器变量也在更新,结果,我不断收到 MySQL 错误 #1054
错误提示
Error Number: 1054
Unknown column 'success' in 'field list'
UPDATE `posts` SET `success` = 0 WHERE `postID` = '1'
型号
public function editpost($postID)
{
$data['success'] = 0;
if($_POST){
$data_post = array(
'title' => $_POST['title'],
'post' => $_POST['post'],
'active' => 1
);
$this->post->update_post($postID, $data);
$data['success'] = 1;
};
$data['post'] = $this->post->get_post($postID);
$this->load->view('edit_post', $data);
}
控制器
public function update_post($postID, $data)
{
$this->db->where('postID', $postID);
$this->db->update('posts', $data);
}
查看
<?php if($success == 1){ ?>
<div style="color: white; background: green;">This post has been updated!</div>
<?php } ?>
<form action="<?=base_url()?>posts/editpost/<?= $post['postID']?>" method="post">
<p>Title: <input type="text" name="title" value="<?= $post['title']?>"></p>
<p>Description: <br><textarea name="post"><?= $post['post']?></textarea></p>
<p><input type="submit" value="Edit Post"></p>
</form>
这是我的数据库表:
【问题讨论】:
-
您的数据库中没有这样的列调用
success -
你的第 1054 行在哪里??
-
成功变量只是一个计数器,不在数据库中
-
告诉我你的第 1054 行。这里没有错误
-
这是错误代码 1054
标签: php mysql codeigniter activerecord