[eluser]lenwood[/eluser]
I'm building a blog, and have coded up an administrative page that allows me to insert the blog entry title, date & time, the body itself, and one category. I have a many-to-many database set up, so the only limitation here is my code. I'm not sure how to pass an array within an array, much less have it execute properly.
Here's my view:
Code:
<h2>Write a New Post Here</h2>
<?php echo form_open('admin/blogback/submit_new'); ?>
<p><input type="text" size="35" name="post_title" /></p>
<p><textarea name="body" id="body"></textarea></p>
<p>Select Categories:</p>
<p><?php foreach($categories as $row): ?>
<input type="checkbox" name="cat_id" value="<?php echo $row->id; ?>" /><?php echo $row->name; ?><br />
<?php endforeach; ?></p>
<p><input type="submit" value="Submit" /></p>
</form>
The controller:
Code:
function submit_new()
{
$this->load->model('blogback_model');
$x = $this->input->post('post_title');
$ptitle = url_title($x, 'dash', TRUE);
$data['date_time'] = standard_date('DATE_W3C', time());
$data['post_title'] = $x;
$data['post_slug'] = $ptitle;
$data['body'] = $this->input->post('body');
$data['cat_id'] = $this->input->post('cat_id');
$this->blogback_model->submit_entry($data);
redirect('admin/blogback');
}
And my model:
Code:
function submit_entry($data)
{
$this->db->set('date_time', element('date_time', $data));
$this->db->set('post_title', element('post_title', $data));
$this->db->set('post_slug', element('post_slug', $data));
$this->db->set('body', element('body', $data));
$this->db->insert('entries');
$poca['entry_id'] = $this->db->insert_id();
$poca['cat_id'] = element('cat_id', $data);
$this->db->insert('post_cat', $poca);
}
This code works if I select just one category, but if I check more than one then its the bottom-most value that gets saved. Please help.