CodeIgniter Forums
What am i doing wrong! - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: What am i doing wrong! (/thread-51500.html)

What am i doing wrong! - El Forum - 05-07-2012


my <?php echo form_dropdown('leraardropdown', $leraardropdown ); ?>
had the wrong name lol -_-'

Hey there,

Currently i am working on a school project where i am making a system for a highschool.

Now i created the database and i am trying to insert a form into the "klas" but i get the following error

Error Number: 1452

Cannot add or update a child row: a foreign key constraint fails (`las`.`klas`, CONSTRAINT `mentorID` FOREIGN KEY (`mentorID`) REFERENCES `leraar` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION)

INSERT INTO `klas` (`klasnaam`, `mentorID`, `jaar`, `niveau`) VALUES ('test', 0, 0, 0)

Filename: /models/insert_model.php

Line Number: 17

I just noticed that i dont give any values to the model, can someone here see where it goes wrong?

My controller is as follows:
function toevoegen(){

function insertKlas()

   $this->db->insert('klas', Array(
  'klasnaam' => $this->input->post('klasnaam'),
  'mentorID' => $this->input->post('leraardropdown'),
  'jaar' => $this->input->post('jaar'),
  'niveau' => $this->input->post('niveau')));
  echo "Klas is toegevoegd";

and my view
<div class="contentvak">
&lt;?php $attributes = array('class' => 'klastoevoegen', 'id' => 'klasform');
echo form_open('klas/toevoegen', $attributes);
    $klasnaam = array(
              'name'        => 'klasnaam',
              'id'          => 'klasnaam',
              'maxlength'   => '100',
              'size'        => '10'

    $jaar = array(
              'jaar'        => 'jaar',
              'id'          => 'jaar',
              'maxlength'   => '100',
              'size'        => '5'

    $niveau = array(
              'niveau'      => 'niveau',
              'id'          => 'niveau',
              'maxlength'   => '100',
              'size'        => '5'

<label>Klasnaam:</label> &lt;?php echo form_input($klasnaam); ?&gt;<br />

&lt;?php echo form_dropdown('mentor', $leraardropdown ); ?&gt;

<label>Jaar:</label> &lt;?php echo form_input($jaar); ?&gt;<br />

<label>Niveau:</label> &lt;?php echo form_input($niveau); ?&gt;<br />

&lt;?php echo form_submit('submit', 'Voeg klas toe'); ?&gt;

&lt;?php echo form_close(); ?&gt;

Please help Big Grin