php - Product category id is not working on product form in CodeIgniter -
i'm making website users can add products website. when select category on product form view file , upload product, no category id given product , says category id = 0.
some database information: categories table: row 1: id row 2: name in products table: row: category_id
this dropdown menu categories in view form file:
<select name="category_id"> <?php foreach (get_categories_h() $category) : ?> <option><?php echo $category['name']; ?></option> <?php endforeach; ?> </select>
and part of db insert function in controller form:
$this-> db-> insert('products', array( 'product_foto' => 'new_'.$data["raw_name"].$data['file_ext'], 'product_foto_thumb' => 'thumb_'.$datathumb["raw_name"].$datathumb['file_ext'], 'product_naam' => $this->input->post('product_naam'), 'product_beschrijving' => $this->input->post('product_beschrijving'), 'ophaal_plaats' => $this->input->post('ophaal_plaats'), 'category_id' => $this->input->post('category_id'), 'date_created' => date('y-m-d'), 'date_updated' => date('y-m-d') );
i hope can me, thanks
you can try solution problem.
change view file
<select name="category_id"> <?php foreach (get_categories_h() $category) : ?> <option value="<?=$category['id'];?>"><?php echo $category['name']; ?></option> <?php endforeach; ?> </select>
changes controller file.
$this-> db-> insert('products', array( 'product_foto' => 'new_'.$data["raw_name"].$data['file_ext'], 'product_foto_thumb' => 'thumb_'.$datathumb["raw_name"].$datathumb['file_ext'], 'product_naam' => $this->input->post('product_naam'), 'product_beschrijving' => $this->input->post('product_beschrijving'), 'ophaal_plaats' => $this->input->post('ophaal_plaats'), 'category_id' => !empty($this->input->post('category_id')) ? $this->input->post('category_id') : 0, 'date_created' => date('y-m-d'), 'date_updated' => date('y-m-d') );
i hope helps you.
Comments
Post a Comment