im试图将数据输入数据库, 但它不起作用。 数据未插入
控制器
public function simpan(){
$data1 = [
"idtransaksi" => $this->input->post('id_transaksi'),
"idbuku" => $this->input->post('kode_buku'),
"nis" => $this->input->post('nis'),
"nama" => $this->input->post('nama'),
"tglkembali" => $this->input->post('tanggal_kembali'),
"status_denda" => $this->input->post('status_denda'),
"keterangan" => $this->input->post('keterangan')
];
$this->Kembali_models->simpan($data1);
$result = $this->db->affected_rows();
if($result > 0){
echo "<script>
alert('Data berhasil di tambah');
window.location.href='".base_url().'kembali'."';
</script>";
} else {
echo "<script>
alert('Data gagal di tambah');
window.location.href='".base_url().'kembali'."';
</script>";
}
}
模型
public function simpan($data1){
$this->db->insert('tb_pengembalian',$data1);
}
视图
<div class="content-wrapper">
<div class="panel-body">
<?php echo validation_errors(); ?>
<?php echo form_open('Kembali/simpan'); ?>
some long code
<div class="col-sm-1">
<button type="submit" name="simpan" class="btn btn-primary">Simpan</button>
</div>
</form>
</div>
</div>
试图检查所有内容
警报消息显示为“ Data gagal di tambah”。
控制器有什么问题吗?
答案 0 :(得分:0)
请检查控制器上是否调用了模型。
$this->Kembali_models->simpan($data1);
suggestion
$this->kembali_models->simpan($data1);