I am just new in CodeIgniter. After executing the program, every time I submit the form I'm always receiving this (in the picture)php error
Heres my code...
item_model.php (model)
class Item_model extends CI_Model
{
public function insertItem()
{
$code = $this->input->post('prod_code');
$name = $this->input->post('prod_name');
$category = $this->input->post('category');
$price = $this->input->post('price');
$sql = "INSERT INTO `system`.`products` (`prod_code`,`prod_name`,`category_id`,`original_price`) VALUES ("
.$this->db->escapeString($code).", ".$this->db->escapeString($name)
.",(select category_id from category where category_name = "
.$this->db->escapeString($category)."), "
.$this->db->escapeString($price).")";
$result = $this->db->query($sql);
if($this->db->affected_row() === 1)
{
$this->session->set_flashdata('successMessage',
'<div class="alert alert-success">New product has been registered</div>');
redirect(base_url('new_item'));
}
}
}
item_con.php (controller)
public function item_con()
{
$this->form_validation->set_rules('prod_name', 'Product Name', 'required|min_length[3]');
$this->form_validation->set_rules('price', 'Original Price', 'required|integer');
if($this->form_validation->run() == FALSE)
{
$this->session->set_flashdata('errorMessage', '<div class="alert alert-danger">'.validation_errors().'</div>');
redirect(base_url('new_item'));
}
else
{
$this->load->model('item_model');
$result = $this->item_model->insertItem();
if($result)
{
$this->session->set_flashdata('successMessage',
'<div class="alert alert-success">New product has been registered</div>');
redirect(base_url('new_item'));
}
}
}
I just want to insert the product details in the products table. The category_id is foreign key in product table. And I want that everytime I insert the product details, it reads the category_id of the product from category table. I hope you could help. Thanks