2017-09-12 7 views
0

Je crée un site Web afin que les utilisateurs peuvent ajouter des produits sur le site. Mais lorsque je sélectionne une catégorie dans mon dossier de vue sous forme de produits et je télécharger le produit, aucun identifiant de catégorie est donnée au produit et il dit la catégorie id = 0.La catégorie de produit id ne fonctionne pas sur la forme du produit dans CodeIgniter

Some database information: 

categories table: 
Row 1: id 
Row 2: name 

In the products table: 
Row: category_id 

Ceci est mon menu déroulant pour les catégories à mon avis fichier forme:

<select name="category_id"> 
     <?php foreach (get_categories_h() as $category) : ?> 
      <option><?php echo $category['name']; ?></option> 
     <?php endforeach; ?> 
     </select> 

Et cela fait partie de ma fonction d'insertion db dans mon contrôleur pour ma forme:

$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') 
      ); 

J'espère que quelqu'un peut me aider, grâce

Répondre

1

vous pouvez essayer cette solution à votre problème.

Changer votre fichier de vue

<select name="category_id"> 
     <?php foreach (get_categories_h() as $category) : ?> 
      <option value="<?=$category['id'];?>"><?php echo $category['name']; ?></option> 
     <?php endforeach; ?> 
</select> 

Modifie votre fichier contrôleur.

$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') 
      ); 

J'espère que cela vous aide.

+0

Merci monsieur pour m'aider ça marche maintenant – lablanco

0

essayez celui-ci

<select name="category_id"> 
     <?php foreach (get_categories_h() as $category) : ?> 
      <option value="<?=$category['id'];?>"><?php echo $category['name']; ?></option> 
     <?php endforeach; ?> 
</select>