Welcome Guest, Not a member yet? Register   Sign In
Having trouble updating my database with CodeIgniter
#10

[eluser]cvandal[/eluser]
OK,

I've created a new view with a separate form for updating. I've used the form helper to select what information is loaded into the form when you click on the 'Update' link.

When the page loads, I get 2 errors, 'Undefined variable: title' and 'Undefined variable: content'.

I thought the variables would be loaded by these functions in my controller when it performs a query:
Code:
function update()
        {
            $data = array();
            if($query = $this->crud_model->get_entry())
            {
                $data['pages'] = $query;
            }
            $this->load->view('update_view', $data);
        }
        function update_page()
        {
            $data = array(
                'title' => $this->input->post('title'),
                'content' => $this->input->post('content')
            );
            $this->crud_model->update_entry($data);
            redirect('');
        }

The Model:
Code:
function update_entry($data)
        {
            $this->db->update('pages', $data);
            return $data->row();
        }

The view which contains the option to update:
Code:
<p>&lt;?=anchor("crud/update/$row->id", 'Update'); ?&gt;</p>

The view which contains the form which should be automatically populated when the user clicks on the 'Update' link in the previouse view:
Code:
&lt;?=form_open('crud/update_page') ?&gt;
            <p>
                <label for="title">Title:</label>
                &lt;input type="text" name="title" id="title" value="&lt;?=$title?&gt;" /&gt;
            </p>
            <p>
                <label for="content">Content:</label>
                &lt;textarea name="content" id="content"&gt;&lt;?=$content?&gt;&lt;/textarea&gt;
            </p>
            <p>
                &lt;input type="submit" value="Update" /&gt;
            </p>
        &lt;/form&gt;


Messages In This Thread
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 09:00 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 09:26 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 09:28 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 10:06 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 10:40 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 11:54 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-10-2009, 11:58 PM
Having trouble updating my database with CodeIgniter - by El Forum - 09-11-2009, 12:27 AM
Having trouble updating my database with CodeIgniter - by El Forum - 09-11-2009, 01:47 AM
Having trouble updating my database with CodeIgniter - by El Forum - 09-11-2009, 07:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB