Я создал страницу формы, на которую будет отправлена таблица базы данных профиля студента, к которой были присоединены. Но некоторые данные не могут быть загружены в базу данных и считаются нулевыми. Нулевые разборчивые данные - это данные, которые были связаны с другими таблицами с использованием идентификатора. Это ошибка массажа:
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails (`elsi`.`placement_test`, CONSTRAINT `placement_test_ibfk_1` FOREIGN KEY (`id_teacher`) REFERENCES `teacher` (`id_teacher`) ON DELETE CASCADE ON UPDATE CASCADE)
INSERT INTO placement_test (id_student, id_class, date_test, id_teacher, ket, time_e, time_s) VALUES ('', '', '2020-02-26', '', 'dmwkfmw', '13:00', '')
Это мой модельный скрипт:
public function get_place()
{
$this->db->select('*');
$this->db->from('placement_test');
$this->db->join('students','students.id_student=placement_test.id_student');
$this->db->join('teacher','teacher.id_teacher=placement_test.id_teacher');
$this->db->join('class','class.id_class=placement_test.id_class');
$query = $this->db->get();
return $query;
}
public function insert($id_student, $id_class, $date_test, $id_teacher, $ket, $time_e, $time_s)
{
$hsl=$this->db->query("INSERT INTO placement_test (id_student, id_class, date_test, id_teacher, ket, time_e, time_s) VALUES ('$id_student', '$id_class', '$date_test', '$id_teacher', '$ket', '$time_e', '$time_s')");
return $hsl;
}
Это мой скрипт контроллера:
public function add(){
$name_student = $this->input->post('id_student');
$class_level = $this->input->post('id_class');
$date_test = $this->input->post('date_test');
$name_teacher = $this->input->post('id_teacher');
$ket = $this->input->post('ket');
$time_s = $this->input->post('time_s');
$time_e = $this->input->post('time_e');
$data = array(
'id_student' => $name_student,
'id_class' => $class_level,
'date_test' => $date_test,
'id_teacher' => $name_teacher,
'ket' => $ket,
'time_s' => $time_s,
'time_e' => $time_e
);
$this->Mplacement_test->insert($name_student, $class_level, $date_test, $name_teacher, $ket, $time_e, $time_s);
redirect('academic/placement_test');
}
И это мое мнение скрипт:
<form method="POST" action="<?php echo base_url();?>index.php/academic/Placement_test/add">
<h3 class="text-center">Tambah Jadwal Placement Test</h3>
<div class="form-group">
<label for="exampleFormControlInput1">Nama Murid</label>
<div class="form-group">
<select class="form-control" id="exampleFormControlInput1">
<option value="">Pilih Siswa</option>
<?php foreach ($place->result() as $key => $data) { ?>
<option value="<?=$data->id_teacher?>"><?=$data->name_student?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Pilihan Kelas</label>
<select class="form-control" name="class_level" id="exampleFormControlSelect1">
<option>Pilih Kelas</option>
<?php foreach ($place->result() as $key => $data) { ?>
<option value="<?=$data->id_class?>"><?=$data->class_level?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect2">Jadwal Test</label>
<input type="date" name="date_test" class="form-control" id="exampleFormControlSelect2">
</div>
<div class="form-group">
<label for="time_start">Waktu Mulai</label>
<input type="time" name="time_e" class="form-control">
</div>
<div class="form-group">
<label for="time_start">Waktu selesai</label>
<input type="time" name="time_e" class="form-control">
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Guru Pendamping</label>
<select class="form-control" id="exampleFormControlSelect2">
<option value="">Pilih Guru</option>
<?php foreach ($place->result() as $key => $data) { ?>
<option value="<?=$data->id_teacher?>"><?=$data->name_teacher?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Catatan</label>
<textarea name="ket" class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-primary float-right">
Add New Placement Test
</button>
</form>
Что-то не так в моем скрипте? Кто-нибудь может мне помочь, пожалуйста?