title: Database insertion codeigniter
body: <p>I was working on a project and here's the code,the problem is that I want to add the $newRapport array values (VIS_MATRICULE, RAP_NUM) also in $newMedicament.
      if(isset($_POST['add_rapport'])){</p>
  
  <pre><code>$newRapport = array (//'VIS_MATRICULE'=&gt;$this-&gt;input-&gt;post('VIS_MATRICULE'), 
                  'VIS_MATRICULE'=&gt;$_POST['VIS_MATRICULE'],
              'RAP_NUM'=&gt; '',
              'PRA_NUM'=&gt;$_POST['PRA_NUM'],
              'RAP_DATE'=&gt;$_POST['RAP_DATE'],
              'RAP_BILAN'=&gt;$_POST['RAP_BILAN'],
              'RAP_MOTIF'=&gt;$_POST['RAP_MOTIF']);
                   $this-&gt;db-&gt;insert('rapport_visite', $newRapport);
  
           // Pour Les Composants
  
                         //Pour les Médicaments                      
  $newMedicament = array ('VIS_MATRICULE'=&gt;$_POST['VIS_MATRICULE'],
                          'RAP_NUM'=&gt; '',
                          'MED_DEPOTLEGAL'=&gt;$_POST['MED_DEPOTLEGAL'],
                          'OFF_QTE'=&gt;$_POST['OFF_QTE']) ;
                   $this-&gt;db-&gt;insert('offrir', $newMedicament);
  
          }
  </code></pre>
  
  <p>the problem is that it says:</p>
  
  <pre><code>A Database Error Occurred
  
  Error Number: 1452
  
  Cannot add or update a child row: a foreign key constraint fails (`swissvisite`.`offrir`, CONSTRAINT `offrir_ibfk_2` FOREIGN KEY (`VIS_MATRICULE`, `RAP_NUM`) REFERENCES `rapport_visite` (`VIS_MATRICULE`, `RAP_NUM`))
  
  INSERT INTO `offrir` (`VIS_MATRICULE`, `RAP_NUM`, `MED_DEPOTLEGAL`, `OFF_QTE`) VALUES ('a131', '', 'EVILR7', '2')
  
  Filename: C:\wamp\www\code\system\database\DB_driver.php
  
  Line Number: 330
  </code></pre>