application/controllers/Pharmacy.php
/*
			* If the validation is not valid, then it redirects to the create page.
			* If the validation for each input field is valid then it inserts the data into the database
			* and it stores the operation message into the session flashdata and display on the manage product page
		*/
If the validation is not valid, then it redirects to the create page.
If the validation for each input field is valid then it inserts the data into the database
and it stores the operation message into the session flashdata and display on the manage product page
If the validation is not valid then it redirects to the create page . If the validation for each input field is valid then it inserts the data into the database and it stores the operation message into the session flashdata and display on the manage product page
public function create()
		{
			if(!in_array('createProduct', $this->permission)) {
				redirect('dashboard', 'refresh');
			}
			if ($this->form_validation->run() == TRUE) {
				$upload_image = $this->upload_image();
				$data = array(
				'name' => $this->input->post('product_name'),
				'sku' => $this->input->post('sku'),
				'cost_price' => $this->input->post('cost_price'),
				'price' => $this->input->post('price'),
				'qty' => $this->input->post('qty'),
				'image' => $upload_image,
				'description' => $this->input->post('description'),
				'attribute_value_id' => json_encode($this->input->post('attributes_value_id')),
				'brand_id' => json_encode($this->input->post('brands')),
				'category_id' => json_encode($this->input->post('category')),
				'store_id' => $this->input->post('store'),
				'availability' => $this->input->post('availability'),
				);
				$create = $this->model_products->create($data);
				if($create == true) {
					$this->session->set_flashdata('success', 'Successfully created');
					redirect('pharmacy/', 'refresh');
				}
				else {
					$this->session->set_flashdata('errors', 'Error occurred!!');
					redirect('pharmacy/create', 'refresh');
				}
			}
			else {
				$this->render_template('pharmacy/create', $this->data);
			}
		}
public function create ( ) { if ( ! in_array ( 'createProduct' , $ this -> permission ) ) { redirect ( 'dashboard' , 'refresh' ) ; } if ( $ this -> form_validation -> run ( ) == TRUE ) { $ upload_image = $ this -> upload_image ( ) ; $ data = array ( 'name' => $ this -> input -> post ( 'product_name' ) , 'sku' => $ this -> input -> post ( 'sku' ) , 'cost_price' => $ this -> input -> post ( 'cost_price' ) , 'price' => $ this -> input -> post ( 'price' ) , 'qty' => $ this -> input -> post ( 'qty' ) , 'image' => $ upload_image , 'description' => $ this -> input -> post ( 'description' ) , 'attribute_value_id' => json_encode ( $ this -> input -> post ( 'attributes_value_id' ) ) , 'brand_id' => json_encode ( $ this -> input -> post ( 'brands' ) ) , 'category_id' => json_encode ( $ this -> input -> post ( 'category' ) ) , 'store_id' => $ this -> input -> post ( 'store' ) , 'availability' => $ this -> input -> post ( 'availability' ) , ) ; $ create = $ this -> model_products -> create ( $ data ) ; if ( $ create == true ) { $ this -> session -> set_flashdata ( 'success' , 'Successfully created' ) ; redirect ( 'pharmacy/' , 'refresh' ) ; } else { $ this -> session -> set_flashdata ( 'errors' , 'Error occurred!!' ) ; redirect ( 'pharmacy/create' , 'refresh' ) ; } } else { $ this -> render_template ( 'pharmacy/create' , $ this -> data ) ; } }
If the validation is not valid, then it redirects to the create page.
If the validation is not valid then it redirects to the create page .
// true case