• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
duplicates when using database update

#1
[eluser]Unknown[/eluser]
Hi.

I have a strange issue here.

can't find anything about it on google or the forum and first time i got this problem with CI.

When i update one of my post from my MySQL DB it makes a duplicate of it and add a new row, it does not take all the info because i don't need to change that.

my code is this

Code:
//model
function edit($options = array(), $site, $edit = FALSE)
    {
if(!$edit)
{
     $db = $this->__dataaseConnection($site);
     $db->select('*');
     $query = $db->get_where('news', array('id'=> $options['id']));
     return $query->result();
}
elseif($edit)
{
     $data = array(
    'headline' => $options['headline'],
    'text' => $options['text'],
    'status' => $options['status']
     );
     $db = $this->__dataaseConnection($site);
     $db->update('news', $data, array('id' => $id));
     redirect('/news/list_entries/' . $site);
}
    }

Code:
//Controller
function edit()
    {
$options = array(
   'headline' => $this->input->post('headline'),
   'text' => $this->input->post('text'),
   'status' => $this->input->post('status'),
   'id' => $this->uri->segment(4)
);

$data['current_view'] = 'news_view';
$this->load->model('news_model');
$data['news'] = $this->news_model->edit($options, $this->uri->segment(3), FALSE);

$this->form_validation->set_rules('headline', 'Headline', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');


if($this->form_validation->run() == TRUE)
{
     $this->load->model('news_model');
     $data['news'] = $this->news_model->add($options, $this->uri->segment(3), TRUE);
}
$this->load->view('includes/template', $data);
    }

my form is looking like this.
http://cl.ly/3e2p0w1j1B1r083S3s38

don't ask about the language, its danish.

when i edit that 3 fields i get this output
http://cl.ly/2z011T0z0Z1p180v103I

i edit the post with ID 3, and it make a new row of that post..
why?

another database update is working just fine.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.