Welcome Guest, Not a member yet? Register   Sign In
Multiple Insert bug
#1

[eluser]Soltic[/eluser]
Hello,

I' m new in this forum and i have one problem:
I try to do multiple insert with my htm form like this:
Code:
<?php $attr = array('id=>sms'); echo form_open('insertsms/journalier',$attr); ?>
       <fieldset>
           <legend>Informations Générales</legend>
       <tr>
          <span>Institution :&lt;input type="text" name="structure"/&gt;&lt;/span>
           <span>Date :&lt;input type="datetime" name="datesms" id="datesms"/&gt;&lt;/span>
       </tr>
       </fieldset>
       <table class="dTable" border="none">
          <thead>
           <tr>
            <th>Pathologie</th>
            <th>Tranche d'Age</th>
            <th>Nombre de cas</th>
            <th>Actions</th>
          </tr>
        </thead>
    <tfoot>
        <tr>
            <th colspan="5">&lt;input type="button" value="Ajouter une ligne" /&gt;&lt;/th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>
                <select name="patho[]">
                <option selected="selected" value="patho">Choisissez une pathologie</option>
                     &lt;?php
                              
                            foreach ($patho as $row)
                               {
                                  echo "<option value='$row-&gt;idpatho'>" . $row->libpatho . "</option>";
                               }
                      ?&gt;
                </select></td>
            <td class="test">
                <select name="tranche[]" id="tranche">
                <option selected="selected" value="tranche">Choisissez une tranche Age</option>
                     &lt;?php
                              
                            foreach ($age as $row)
                               {
                                  echo "<option value='$row-&gt;idtranche'>" . $row->tranche_age . "</option>";
                               }
                      ?&gt;
                </select></td>
            </td>
            <td>&lt;input type="text" name="nbcas[]"/&gt;&lt;/td>
            <td>&lt;input type="button" value="supprimer" /&gt;&lt;/td>
        </tr>
        <tr>
        
    </tbody>
                  
        </tr>
       </table>
       <td>&lt;input type="submit" value="Enregistrer/Envoyer" name="ok" /&gt;&lt;/td>
            <td>&lt;input type="reset" value="Annuelr" name="cancel" /&gt;&lt;/td>
       &lt;?php echo form_close(); ?&gt;

My Controller:
Code:
&lt;?php

class insertsms extends CI_Controller {
    
    function __construct()
    {
        parent::__construct();
    }
    
    
  function journalier()
    {
        $this->form_validation->set_rules('structure','Structure','trim|required|xss_clean');
        $this->form_validation->set_rules('patho[]','Patho','trim|required|xss_clean');
        $this->form_validation->set_rules('tranche[]','Tranche','trim|required|xss_clean');
        $this->form_validation->set_rules('nbcas[]');
        $this->form_validation->set_message('required', 'Veuillez remplir les champs vides');
                
        if($this->form_validation->run())
        {
          
           $structure_id=$this->input->post('strucure');
           $date_sms=$this->input->post('datesms');
           $pathoid[]=$this->input->post('patho');
           $trancheid[]=$this->input->post('tranche');
           $nb_cas[]=$this->input->post('nbcas');
                
          // $this->model_liste->create($data)    
          
                for ($i=0; $i < count($pathoid); $i++) {
                    
                
                $message = array(
                                
                                 'structure_id'=>$structure_id,
                                 'date_sms'=>$date_sms,
                                 'pathoid'=>$pathoid[$i],
                                 'trancheid'=>$trancheid[$i],
                                 'nb_cas'=>$nb_cas[$i]
                                 );
                                
                         }$this->model_liste->create($message);
        }
           else
            {
                
               $this->template->write_view('nav','navigation');
                $this->template->write_view('logo','logo');
                $this->template->render();
                $test['result'] = $this->model_liste->getPathologie();
                 $test['result'] = $this->model_liste->getTrancheAge();
                $this->load->write_view('content','vue_insertsms',$test);
            }
      
  
      
  

}
}
?&gt;

My Model:
Code:
function create($data)
      {
          $this->db->insert_batch('message', $data);
          
      }
Error

Error Number: 1136

Column count doesn't match value count at row 3

INSERT INTO `message` () VALUES (), (), ('patho','PHY','PHY'), ('tranche','n1','n4'), ('','21','23')

Filename: /var/www/senedomaine.com/models/model_liste.php

Line Number: 48
this code doesn't work

Some one can help me
#2

[eluser]Soltic[/eluser]
Hi,
You do not have solutions in relation to my problem ?
#3

[eluser]Soltic[/eluser]
Hi, i changed my code Controller and it look this:

Code:
&lt;?php

class insertsms extends CI_Controller {
    
    function __construct()
    {
        parent::__construct();
    }
    
    
  function journalier()
    {
        $this->form_validation->set_rules('structure','Structure','trim|required|xss_clean');
        $this->form_validation->set_rules('patho[]','Patho','trim|required|xss_clean');
        $this->form_validation->set_rules('tranche[]','Tranche','trim|required|xss_clean');
        $this->form_validation->set_rules('nbcas[]');
        $this->form_validation->set_message('required', 'Veuillez remplir les champs vides');
                
        if($this->form_validation->run())
        {
          
           //$structure_id=$this->input->post('structure');
           $date_sms=$this->input->post('datesms');
           $pathoid=$this->input->post('patho');
           $trancheid=$this->input->post('tranche');
           $nb_cas=$this->input->post('nbcas');
          
                for ($i=1; $i < count($pathoid); $i++) {                              
                  $data = array(
                                'structure_id' =>$this->input->post('structure'),
                                'date_sms' =>$this->input->post('datesms'),
                                'pathoid' =>$this->input->post('patho'.$i),
                                'trancheid' =>$this->input->post('tranche'.$i),
                                'nb_cas' =>$this->input->post('nbcas'.$i)
                                 );
               //$this->model_liste->create($data);
              
                 echo "<pre>";  
               print_r($data);
               echo "</pre>";
                    
                    }
                  
                 }
                
           else
            {
                
               $this->template->write_view('nav','navigation');
                $this->template->write_view('logo','logo');
                $this->template->render();
                $test['result'] = $this->model_liste->getPathologie();
                 $test['result'] = $this->model_liste->getTrancheAge();
                $this->load->write_view('content','vue_insertsms',$test);
            }
      
       }
}
?&gt;


And when i print data i have this result:

Array
(
[structure_id] => 221779128978
[date_sms] => 2012/06/17 04:19
[pathoid] =>
[trancheid] =>
[nb_cas] =>
)
Array
(
[structure_id] => 221779128978
[date_sms] => 2012/06/17 04:19
[pathoid] =>
[trancheid] =>
[nb_cas] =>
)
Array
(
[structure_id] => 221779128978
[date_sms] => 2012/06/17 04:19
[pathoid] =>
[trancheid] =>
[nb_cas] =>
)

there are three field without value.

I need help

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB