Welcome Guest, Not a member yet? Register   Sign In
inserting giving me another row
#1

[eluser]Shiva666[/eluser]
Hi

I'm trying to insert data into my database using a form and active records, but for some reason after I add a record and I check my database two rows have been inserted. One has nothing in it while the other one has the data that I entered.

This is my content controller
Quote:function content_create() {

$data = array(
'title' => $this->input->post('title'),
'content' => $this->input->post('content'),
'meta_title' => $this->input->post('meta_title'),
'meta_description' => $this->input->post('meta_description'),
'meta_keywords' => $this->input->post('meta_keywords')
);



$this->load->model('mdl_content');
$this->mdl_content->create($data);

$data['view_file'] = "create";
$this->load->module('templates');
$this->templates->ci_admin($data);
}

This is my model
Quote:function get_table() {
$table = "content";
return $table;
}

function create($data) {

$table = $this->get_table();

$page_url = url_title($this->input->post('title'), 'dash', TRUE);

$data = array(
'title' => $this->input->post('title'),
'content' => $this->input->post('content'),
'page_url' => $page_url,
'meta_title' => $this->input->post('meta_title'),
'meta_description' => $this->input->post('meta_description'),
'meta_keywords' => $this->input->post('meta_keywords')
);

return $this->db->insert($table, $data);
return;
}

and this is the view
Quote: <h2>Create</h2>

&lt;?php

echo form_open('content/content_create');

?&gt;

<p>
<label for="title">Title:</label>
&lt;input type="text" name="title" id="title" /&gt;
</p>

<p>
<label for="content">Content:</label>
&lt;input type="text" name="content" id="content" /&gt;
</p>

<p>
<label for="meta_title">Meta_Title:</label>
&lt;input type="text" name="meta_title" id="meta_title" /&gt;
</p>

<p>
<label for="meta_description">Meta_Description:</label>
&lt;input type="text" name="meta_description" id="meta_description" /&gt;
</p>

<p>
<label for="meta_keywords">Meta_Keywords:</label>
&lt;input type="text" name="meta_keywords" id="meta_keywords" /&gt;
</p>

&lt;input type="submit" value="Submit" /&gt;

&lt;?php

echo form_close();

?&gt;
#2

[eluser]Flemming[/eluser]
did you find your solution?

Not sure that this will help but just a couple of weird things in your model (create function):

1. you redefine $data
Code:
$data = array(
        ‘title’ => $this->input->post(‘title’),
...

2. you have 2 returns at the end




Theme © iAndrew 2016 - Forum software by © MyBB