0
votes

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:

http://i.stack.imgur.com/DKobX.jpg

2
there is no such column call success in your database - Abdulla Nilam
and where is your line 1054?? - Abdulla Nilam
success variable just a counter, not in database - Yohanes Setiawan
show me your line 1054. there is no error on here - Abdulla Nilam
it was error code 1054 - Yohanes Setiawan

2 Answers

0
votes

Instead of this
$this->post->update_post($postID, $data);

use this
$this->post->update_post($postID, $data_post);

Because the array you are passing is wrong array

0
votes

When a query is executed then it will return true and false value. If a query executes successfully then it will return true otherwise it return false. For example:

    $res = $this->db->where('id',$id)
        ->update('user',$array);
  echo $res;