[英]codeigniter active record update using counter
我想使用活動記錄來更新數據庫,但是我在$ 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>
這是我的數據庫表:
代替這個
$this->post->update_post($postID, $data);
用這個
$this->post->update_post($postID, $data_post);
因為您傳遞的數組是錯誤的數組
執行查詢時,它將返回true和false值。 如果查詢成功執行,則返回true,否則返回false。 例如:
$res = $this->db->where('id',$id)
->update('user',$array);
echo $res;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.