I want to update my database using active record, but the counter variable that I set in $data array is updating too, as a result, I keep getting MySQL error #1054
Error Notes
Error Number: 1054
Unknown column 'success' in 'field list'
UPDATE `posts` SET `success` = 0 WHERE `postID` = '1'
Model
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);
}
Controller
public function update_post($postID, $data)
{
$this->db->where('postID', $postID);
$this->db->update('posts', $data);
}
View
<?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 is my database table:
successin your database - Abdulla Nilam