Search code examples
phphtmlmysqlcodeignitercodeigniter-3

A Database Error Occurred Error Number: 1048 Column 'ket' cannot be null


I got an error that says:

Error Number: 1048 Column 'ket' cannot be null

INSERT INTO tb_uploadv (ket, tgl, video) VALUES (NULL, NULL, NULL)

Filename: C:/xamppV5/htdocs/sicams/system/database/DB_driver.php

Line Number: 691

can all master help me pls.

my controller: controllers/Uploadv.php

<?php
class Uploadv extends CI_Controller{
    public function index(){

    $data['uploadv'] = $this->m_uploadv->tampil_data()->
        result();

        $this->load->view('templates/header');
        $this->load->view('templates/sidebarupv');
        $this->load->view('uploadv', $data);
        $this->load->view('templates/footer');
    }

    public function tambah_aksi()
    {
        $data = [
        'ket'           => $this->input->post('ket'),
        'tgl'           => $this->input->post('tgl'),
        'video'         => $this->input->post('video'),
        
        ];

        $this->m_uploadv->input_data($data, 'tb_uploadv');
        redirect('uploadv/index');
    }
}

?>

my view: views/uploadv.php

 <div class="content-wrapper">
    <section class="container-fluid">
        <h5>
            Data Rekaman
            <small>Silahkan Upload Data Rekaman</small>
        </h5>
    </section>

    <section class="content">
        <button class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-book"></i>Tambah Data</button>
        <table class="table">
            <tr>
                <th>No</th>
                <th>Keterangan</th>
                <th>Tanggal Rekaman</th>
                <th>File Rekaman</th>
            </tr>

            <?php 

                $no = 1;
                foreach ($uploadv as $upv) : ?>
                    <tr>
                        <td><?php echo $no++ ?></td>
                        <td><?php echo $upv->ket ?></td>
                        <td><?php echo $upv->tgl ?></td>
                        <td><?php echo $upv->video ?></td>
                    </tr>

             <?php endforeach; ?>
        </table>
    </section>


<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">FORM UPLOAD REKAMAN</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="post" action="<?php echo base_url().'uploadv/tambah_aksi';?>">

            <div class="form-group">
                <label>Keterangan</label>
                <input type="text" name="keterangan" class="form-control">
            </div>

            <div class="form-group">
                <label>Tanggal Rekaman</label>
                <input type="date" name="tanggal_rekam" class="form-control">
            </div>

            <div class="form-group">
                <label>File Rekaman</label>
                <input type="text" name="bukti" class="form-control">
            </div>

                <button type="reset" class="btn btn-danger"
                 data-dismiss="modal">Batal</button>
        <button type="submit" class="btn btn-primary">Simpan</button>
        </form>
      </div>
   
    </div>
  </div>
</div>
</div>

My Model: models/M_uploadv.php

    <?php 

class M_uploadv extends CI_Model {

    public function tampil_data() 
    {
        return $this->db->get('tb_uploadv');
    }   

    public function input_data($data)
    {
        $this->db->insert('tb_uploadv', $data);
    }
}

Solution

  • You're submitting input field with another names, you input names should be match.

    Try this code.

    public function tambah_aksi()
    {
        $data = [
        'ket'       => $this->input->post('keterangan'),
        'tgl'       => $this->input->post('tanggal_rekam'),
        'video'     => $this->input->post('bukti'),
        ];
    
        $this->m_uploadv->input_data($data, 'tb_uploadv');
        redirect('uploadv/index');
    }