[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">
<?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> <?php echo form_input($klasnaam); ?><br />
<label>Mentor:</label>
<?php echo form_dropdown('mentor', $leraardropdown ); ?>
<label>Jaar:</label> <?php echo form_input($jaar); ?><br />
<label>Niveau:</label> <?php echo form_input($niveau); ?><br />
<?php echo form_submit('submit', 'Voeg klas toe'); ?>
<?php echo form_close(); ?>
</div>
Please help