skip to Main Content

I have an issue with the input in my CodeIgniter. Even though the input form has been filled correctly, Error Number: 1048 still appears. Please help with a solution for this error.

Here is the code for my view, ‘entry.php’:

<?php if($this->session->flashdata('message')) : ?>
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        <?= $this->session->flashdata('message') ?>
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
<?php endif ?>

<form action="" method="POST">

    <div class="card">
        <h5 class="card-header">Entri Kehadiran</h5>
        <div class="card-body"> 
        
    
    
    
            
            <div class="form-group row">
                <label for="time" class="col-sm-2 col-form-label">Jam</label>
                <div class="col-sm-6">
                    <?php date_default_timezone_set('Asia/Jakarta'); ?>
                    <input type="text" class="form-control-plaintext" name="time" value="<?= date('H:i') ?>">
                </div>
            </div>

            <div class="form-group row">
                <label for="date" class="col-sm-2 col-form-label">Tgl/Bln/Thn</label>
                <div class="col-sm-6">
                    <?php date_default_timezone_set('Asia/Jakarta'); ?>
                    <input type="text" class="form-control-plaintext" name="date" value="<?= date('d-M-Y') ?>">
                </div>
            </div>
            
            <div class="form-group row">
    <label for="location" class="col-sm-2 col-form-label">Lokasi Absen</label>
    <div class="col-sm-6">
        <input type="text" class="form-control" name="location" placeholder="Masukkan lokasi absen">
    </div>
</div>

            <div class="form-group row">
                <label for="information" class="col-sm-2 col-form-label">Tgl/Bln/Thn</label>
                <div class="col-sm-6">
                    <a href="<?= base_url('absensi/masuk') ?>" class="btn btn-success mr-3">Masuk</a>
                    <a href="<?= base_url('absensi/ijin') ?>" class="btn btn-warning text-light mr-3">Ijin</a>
                    <a href="<?= base_url('absensi/sakit') ?>" class="btn btn-danger mr-3">Sakit</a>
                </div>
            </div>
        </div>
    </div>
    
</form>


Here is the code for my controller, ‘Absensi.php

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Absensi extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
        is_login();
        $this->load->model('absensi_model', 'absensi');
    }
    
public function entri()
{
    $data['title'] = 'Entri Kehadiran';
    $data['page'] = 'user/kehadiran/entri';

    $this->load->view('templates/app', $data);
}

    public function masuk()
{
    
    $data = [
        'user_id' => $this->session->userdata('id_users'),
        'date' => date('Y-m-d'),
        'time' => date('H:i:s'),
        'information' => 'M',
        'status' => 0,
         'location' => $this->input->post('array_location'), // Menambahkan lokasi
    ];
    $this->absensi->insertEntri($data);
    $this->session->set_flashdata('message', 'Entri kehadiran berhasil. Silahkan tunggu konfirmasi oleh administrator.');

    redirect(base_url('absensi/entri'));
}

    public function ijin()
    {
        $data = [
            'user_id'       => $this->session->userdata('id_users'),
            'date'          => date('Y-m-d'),
            'time'          => date('H:i:s'),
            'information'   => 'I',
            'status'        => 0,
        ];

        $this->absensi->insertEntri($data);
        $this->session->set_flashdata('message', 'Entri kehadiran berhasil. Silahkan tunggu konfirmasi oleh administator.');

        redirect(base_url('absensi/entri'));
    }

    public function sakit()
    {
        $data = [
            'user_id'       => $this->session->userdata('id_users'),
            'date'          => date('Y-m-d'),
            'time'          => date('H:i:s'),
            'information'   => 'S',
            'status'            => 0
        ];

        $this->absensi->insertEntri($data);
        $this->session->set_flashdata('message', 'Entri kehadiran berhasil. Silahkan tunggu konfirmasi oleh administator.');

        redirect(base_url('absensi/entri'));
    }

    public function tabel()
    {
        $data['title']  = 'Tabel Kehadiran';
        $data['page']       = 'user/kehadiran/tabel';
        $data['absensi']    = $this->absensi->getAbsensi();

        $this->load->view('templates/app', $data);
    }

    public function rekap()
    {
        $data['title']  = 'Rekap Kehadiran';
        $data['page']       = 'user/kehadiran/rekap';
        $data['hadir']  = $this->absensi->getHadir();
        $data['ijin']       = $this->absensi->getIjin();
        $data['sakit']  = $this->absensi->getSakit();

        $this->load->view('templates/app', $data);
    }

}

/* End of file Controllername.php */

its an error :

"Please help me with a solution for this issue."

2

Answers


  1. Chosen as BEST ANSWER

    this is my updated view code :

    <?php if($this->session->flashdata('message')) : ?>
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            <?= $this->session->flashdata('message') ?>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    <?php endif ?>
    
    <form action="" method="POST">
    
        <div class="card">
            <h5 class="card-header">Entri Kehadiran</h5>
            <div class="card-body"> 
            
        
        
        
                
                <div class="form-group row">
                    <label for="time" class="col-sm-2 col-form-label">Jam</label>
                    <div class="col-sm-6">
                        <?php date_default_timezone_set('Asia/Jakarta'); ?>
                        <input type="text" class="form-control-plaintext" name="time" value="<?= date('H:i') ?>">
                    </div>
                </div>
    
                <div class="form-group row">
                    <label for="date" class="col-sm-2 col-form-label">Tgl/Bln/Thn</label>
                    <div class="col-sm-6">
                        <?php date_default_timezone_set('Asia/Jakarta'); ?>
                        <input type="text" class="form-control-plaintext" name="date" value="<?= date('d-M-Y') ?>">
                    </div>
                </div>
                
                <div class="form-group row">
        <label for="location" class="col-sm-2 col-form-label">Lokasi Absen</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" name="location"   placeholder="Masukkan lokasi absen">
        </div>
    </div>
    
                <div class="form-group row">
                    <label for="information" class="col-sm-2 col-form-label">Tgl/Bln/Thn</label>
                    <div class="col-sm-6">
                        <a href="<?= base_url('absensi/masuk') ?>" class="btn btn-success mr-3">Masuk</a>
                        <a href="<?= base_url('absensi/ijin') ?>" class="btn btn-warning text-light mr-3">Ijin</a>
                        <a href="<?= base_url('absensi/sakit') ?>" class="btn btn-danger mr-3">Sakit</a>
                    </div>
                </div>
            </div>
        </div>
        
    </form>

    and this the controller :

    <?php 
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class Absensi extends CI_Controller {
        
        public function __construct()
        {
            parent::__construct();
            is_login();
            $this->load->model('absensi_model', 'absensi');
        }
        
    public function entri()
    {
        $data['title'] = 'Entri Kehadiran';
        $data['page'] = 'user/kehadiran/entri';
    
        $this->load->view('templates/app', $data);
    }
    
        public function masuk()
    {
        
        $data = [
            'user_id' => $this->session->userdata('id_users'),
            'date' => date('Y-m-d'),
            'time' => date('H:i:s'),
            'information' => 'M',
            'status' => 0,
             'location' => $this->input->post('location'), // Menambahkan lokasi
        ];
        $this->absensi->insertEntri($data);
        $this->session->set_flashdata('message', 'Entri kehadiran berhasil. Silahkan tunggu konfirmasi oleh administrator.');
    
        redirect(base_url('absensi/entri'));
    }
    
        public function ijin()
        {
            $data = [
                'user_id'       => $this->session->userdata('id_users'),
                'date'          => date('Y-m-d'),
                'time'          => date('H:i:s'),
                'information'   => 'I',
                'status'        => 0,
                'location' => $this->input->post('location'), // Menambahkan lokasi
            ];
    
            $this->absensi->insertEntri($data);
            $this->session->set_flashdata('message', 'Entri kehadiran berhasil. Silahkan tunggu konfirmasi oleh administator.');
    
            redirect(base_url('absensi/entri'));
        }
    
        public function sakit()
        {
            $data = [
                'user_id'       => $this->session->userdata('id_users'),
                'date'          => date('Y-m-d'),
                'time'          => date('H:i:s'),
                'information'   => 'S',
                'status'            => 0,
                'location' => $this->input->post('location'), // Menambahkan lokasi
            ];
    
            $this->absensi->insertEntri($data);
            $this->session->set_flashdata('message', 'Entri kehadiran berhasil. Silahkan tunggu konfirmasi oleh administator.');
    
            redirect(base_url('absensi/entri'));
        }
    
        public function tabel()
        {
            $data['title']  = 'Tabel Kehadiran';
            $data['page']       = 'user/kehadiran/tabel';
            $data['absensi']    = $this->absensi->getAbsensi();
    
            $this->load->view('templates/app', $data);
        }
    
        public function rekap()
        {
            $data['title']  = 'Rekap Kehadiran';
            $data['page']       = 'user/kehadiran/rekap';
            $data['hadir']  = $this->absensi->getHadir();
            $data['ijin']       = $this->absensi->getIjin();
            $data['sakit']  = $this->absensi->getSakit();
    
            $this->load->view('templates/app', $data);
        }
    
    }
    
    /* End of file Controllername.php */

    Please correct my code.


  2. The "name" attribute of your form-control is set to "location":

     <input type="text" class="form-control" name="location" placeholder="Masukkan lokasi absen">
    

    However, you are receiving it on the backend side as "array_location"

    'location' => $this->input->post('array_location')
    

    Since $this->input->post cannot find the "array_location" variable, it will try to inject a NULL value onto the database. Therefore, I suggest changing it to:

    'location' => $this->input->post('location')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search