Welcome Guest, Not a member yet? Register   Sign In
What am i doing wrong!
#1

[eluser]Dizza[/eluser]
PROBLEM IS FIXED!

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

Code:
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:
Code:
function toevoegen(){
  $this->load->model('klas_model');
  if($this->input->post('submit')){
      
  $this->insert_model->insertKlas();
  }
  $this->load->view('klastoevoegen_view');
  }

model
Code:
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";
  return;
}

and my view
Code:
<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'
             );
    
?&gt;

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

&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;
</div>

Please help Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB