• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strange model behaviour

#1
[eluser]joeizang[/eluser]
hi guys,

sorry I have something strange happening between a model and controller.

Basically I would like to capture comments from the users of the application so having written my code, i get the following the error:

<div id="content">
<h1>A Database Error Occurred</h1>
<p>You must use the "set" method to update an entry.</p>
</div>
but I am not updating, I am just inserting into my db into a table called comments: Here is my code, is there something here that I am not seeing?
(Model)
Code:
function createcomment($data)
{
  $this->db->insert('comments',$data);
  return $this->db->insert();
}

Controller
Code:
function addcomments()
{
$this->form_validation->set_rules('name','Your Name','trim|required|xss_clean');
$this->form_validation->set_rules('email','YourEmailAddress','trim|required|xss_clean|valid_email');
            $this->form_validation->set_rules('comments','Comments','required|trim|xss_clean');
            
if($this->form_validation->run() == FALSE)
{
  echo validation_errors();
} else {
  $data = array(
     'commentname' => $this->input->post('name'),
     'commentemail' => $this->input->post('email'),
     'commentbody' => $this->input->post('comments')
);
$this->comments->createcomment($data);
$this->load->view('editorfiles/successful');
  }
}

Thanks for being great guys

#2
[eluser]InsiteFX[/eluser]
Code:
$array = array('name' => $name, 'title' => $title, 'status' => $status);

$this->db->set($array);
$this->db->insert('mytable');

Enjoy
InsiteFX

#3
[eluser]joeizang[/eluser]
hey thanks for the reply,

I made the change to my model, I also realized that this is written about in the documentation so i read it and still it's saying the same thing.

h1>A Database Error Occurred</h1>
<p>You must use the "set" method to update an entry.</p>

I wanted to say that I wrote another model, but did not have this problem. I don't know what I am doing wrong, but can is there anything else I should be doing?

Code:
function createcomment($data)
{
$this->db->set($data);
$this->db->insert('comments');
return $this->db->insert();
}

#4
[eluser]BrianDHall[/eluser]
Code:
function createcomment($data)
{
$this->db->set($data);
return $this->db->insert('comments');
}

Not sure why you call insert twice, so try changing as above.

#5
[eluser]joeizang[/eluser]
Thanks BrainDHall,

I guess it's just plenny caffine and long hours.

Many thanks


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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