The Codeigniter update query does not work with the form

advertisements

Hey guys I'm having trouble running an update query through a form in codeigniter. There is no error returned, but the query does not update in the database. It should be noted there's another form on the same page running an insert query that works fine.

View:

            <?php
                $modify = array(
                    'id' => 'modify-form',
                    'class' => ''
                );
                echo form_open('main/modify_idea', $modify);
                $ta_modify = array(
                    'id' => $row->id,
                    'name' => 'ta_modify',
                    'label' => 'ta_modify',
                    'placeholder' => $row->idea,
                    'method' => 'Post'
                );
                echo form_textarea($ta_modify);
                echo form_hidden('facebook_id', $session['id']);
                echo "<div id='button'>";
                echo form_submit('submit', 'Post');
                echo "</div>";
                echo form_close();
            ?>

Controller:

public function modify_idea() {
    $this->load->model('idea');
    $this->idea->modify_idea();
    redirect('main/members');
}

Model:

public function modify_idea() {
    $data = array(
        'id' => $this->input->post('id'),
        'idea' => $this->input->post('ta_modify'),
        'facebook_id' => $this->input->post('facebook_id')
    );

    $query = $this->db->query("UPDATE idea SET `idea` = ? WHERE `id` =?", array($data['idea'], $data['id']));
    return $query;
}

I've utilized the following resources but still no luck:
CodeIgniter MySQL query not working

CodeIgniter MySQL Query not returning any data, even though there definitely is data to be returned!

http://www.tutorialspoint.com/mysql/mysql-update-query.htm
http://ellislab.com/codeigniter/user-guide/database/active_record.html#delete

As always, thanks for the help!


Pass your post data from controller to model

Change your controller code:

public function modify_idea() {
    $this->load->model('idea');
     $data = array(
        'id' => $this->input->post('id'),
        'idea' => $this->input->post('ta_modify'),
        'facebook_id' => $this->input->post('facebook_id')
    );
    $this->idea->modify_idea($data);
    redirect('main/members');
}

in model do this

public function modify_idea($data) {
   $query = $this->db->query("UPDATE idea SET `idea` = ? WHERE `id` =?",
                           array($data['idea'], $data['id']));
   return $query;
}