[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 :<input type="text" name="structure"/></span>
<span>Date :<input type="datetime" name="datesms" id="datesms"/></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"><input type="button" value="Ajouter une ligne" /></th>
</tr>
</tfoot>
<tbody>
<tr>
<td>
<select name="patho[]">
<option selected="selected" value="patho">Choisissez une pathologie</option>
<?php
foreach ($patho as $row)
{
echo "<option value='$row->idpatho'>" . $row->libpatho . "</option>";
}
?>
</select></td>
<td class="test">
<select name="tranche[]" id="tranche">
<option selected="selected" value="tranche">Choisissez une tranche Age</option>
<?php
foreach ($age as $row)
{
echo "<option value='$row->idtranche'>" . $row->tranche_age . "</option>";
}
?>
</select></td>
</td>
<td><input type="text" name="nbcas[]"/></td>
<td><input type="button" value="supprimer" /></td>
</tr>
<tr>
</tbody>
</tr>
</table>
<td><input type="submit" value="Enregistrer/Envoyer" name="ok" /></td>
<td><input type="reset" value="Annuelr" name="cancel" /></td>
<?php echo form_close(); ?>
My Controller:
Code:
<?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);
}
}
}
?>
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