[eluser]Unknown[/eluser]
Hi Everyone - I am totally new to codeignitor and fairly new to php so please excuse my rookie question.
I am adding a record to a database and want to return load a different view if the addition to the database has been successful. I decided that using the affected_rows() function might be a good way to do this.
this is my controller code
Code:
function insert_product(){
$this->load->model('admin_model');
if($this->input->post('submit')){
$companies_id = $this->input->xss_clean($this->input->post('companies_id'));
$product_description = $this->input->xss_clean($this->input->post('product_description'));
$price = $this->input->xss_clean($this->input->post('price'));
$products_comments = $this->input->xss_clean($this->input->post('products_comments'));
$this->admin_model->add_product($product_description, $price, $products_comments);
}
$this->load->view('insert_product', $data);
}]
my model code is as follows.
Code:
function add_product ($companies_id, $product_description, $price, $product_comments){
$data = array(
'companies_id' => $companies_id,
'product_description' => $product_description,
'price' => $price,
'product_comments' => $product_comments
);
$this->db->insert('products', $data);
I have tried every way that I can think of the return the effected rows to the controller, however my variable never seems to contain any data.
Can anyone shead any light on the best way to do this.
Many thanks