Welcome Guest, Not a member yet? Register   Sign In
A PHP Error was encountered Severity: Notice Message: Undefined index: Satker

I am very confused of this error messages. Please help me

Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined index: Satker
Filename: controllers/Members.php
Line Number: 67
File: C:\xampp\htdocs\nonameapp\application\controllers\Members.php
Line: 67
Function: _error_handler
File: C:\xampp\htdocs\nonameapp\index.php
Line: 315
Function: require_once

Quote:A Database Error Occurred
Error Number: 1048
Column 'satker' cannot be null
INSERT INTO `t_satker` (`kode`, `satker`, `created`, `modified`) VALUES ('asas', NULL, '2019-10-14 13:29:23', '2019-10-14 13:29:23')
Filename: C:/xampp/htdocs/nonameapp/system/database/DB_driver.php
Line Number: 691

This is my controller
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Members extends CI_Controller {
    function __construct() {
        // Load member model
        // Load form validation library
        // Load file helper
    public function index(){
        $data = array();
        // Get messages from the session
            $data['success_msg'] = $this->session->userdata('success_msg');
            $data['error_msg'] = $this->session->userdata('error_msg');
        // Get rows
        $data['members'] = $this->member->getRows();
        // Load the list page view
        $this->load->view('members/index', $data);
    public function import(){
        $data = array();
        $memData = array();
        // If import request is submitted
            // Form field validation rules
            $this->form_validation->set_rules('file', 'CSV file', 'callback_file_check');
            // Validate submitted form data
            if($this->form_validation->run() == true){
                $insertCount = $updateCount = $rowCount = $notAddCount = 0;
                // If file uploaded
                    // Load CSV reader library
                    // Parse data from CSV file
                    $csvData = $this->csvreader->parse_csv($_FILES['file']['tmp_name']);
                    // Insert/update CSV data into database
                        foreach($csvData as $row){ $rowCount++;
                            // Prepare data for DB insertion
                            $memData = array(
                                'kode' => $row['Kode'],
                                'satker' => $row['Satker'],
                            // Check whether email already exists in the database
                            $con = array(
                                'where' => array(
                                'returnType' => 'count'
                            $prevCount = $this->member->getRows($con);
                            if($prevCount > 0){
                                // Update member data
                                $condition = array();
                                $update = $this->member->update($memData, $condition);
                                // Insert member data
                                $insert = $this->member->insert($memData);
                        // Status message with imported data count
                        $notAddCount = ($rowCount - ($insertCount + $updateCount));
                        $successMsg = 'Members imported successfully. Total Rows ('.$rowCount.') | Inserted ('.$insertCount.') | Updated ('.$updateCount.') | Not Inserted ('.$notAddCount.')';
                        $this->session->set_userdata('success_msg', $successMsg);
                    $this->session->set_userdata('error_msg', 'Error on file upload, please try again.');
                $this->session->set_userdata('error_msg', 'Invalid file, please select only CSV file.');
     * Callback function to check file value and type during validation
    public function file_check($str){
        $allowed_mime_types = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain');
        if(isset($_FILES['file']['name']) && $_FILES['file']['name'] != ""){
            $mime = get_mime_by_extension($_FILES['file']['name']);
            $fileAr = explode('.', $_FILES['file']['name']);
            $ext = end($fileAr);
            if(($ext == 'csv') && in_array($mime, $allowed_mime_types)){
                return true;
                $this->form_validation->set_message('file_check', 'Please select only CSV file to upload.');
                return false;
            $this->form_validation->set_message('file_check', 'Please select a CSV file to upload.');
            return false;

And this is view
<div class="container">
    <h2>Members List</h2>
    <!-- Display status message -->
    <?php if(!empty($success_msg)){ ?>
    <div class="col-xs-12">
        <div class="alert alert-success"><?php echo $success_msg; ?></div>
    <?php } ?>
    <?php if(!empty($error_msg)){ ?>
    <div class="col-xs-12">
        <div class="alert alert-danger"><?php echo $error_msg; ?></div>
    <?php } ?>
    <div class="row">
        <!-- Import link -->
        <div class="col-md-12 head">
            <div class="float-right">
                <a href="javascript:void(0);" class="btn btn-success" onclick="formToggle('importFrm');"><i class="plus"></i> Import</a>
        <!-- File upload form -->
        <div class="col-md-12" id="importFrm" style="display: none;">
            <form action="<?php echo base_url('members/import'); ?>" method="post" enctype="multipart/form-data">
                <input type="file" name="file" />
                <input type="submit" class="btn btn-primary" name="importSubmit" value="IMPORT">
        <!-- Data list table -->
        <table class="table table-striped table-bordered">
            <thead class="thead-dark">
                    <th>Kode Satker</th>
                    <th>Nama Satker</th>
                <?php if(!empty($members)){ foreach($members as $row){ ?>
                    <td><?php echo $row['id']; ?></td>
                    <td><?php echo $row['kode']; ?></td>
                    <td><?php echo $row['satker']; ?></td>
                <?php } }else{ ?>
                <tr><td colspan="5">No member(s) found...</td></tr>
                <?php } ?>

function formToggle(ID){
    var element = document.getElementById(ID);
    if(element.style.display === "none"){
        element.style.display = "block";
        element.style.display = "none";


Have you tried testing the insert statement to see if it is correct?

Hi alazhar.faiz,

You could also try making sure that the database definition allows NULL in the table.

The error suggests that the "satker" column is defined as NOT NULL. Or you could change the hard coded NULL into "", which would insert a string (assuming it is a string of course), or the correct dummy type.

If the error is from the imported data, then check the source data for a NULL value.

If this has to do with Expression Engine ie:EE then you are in the wrong forums.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 05-02-2021, 06:59 AM by includebeer. Edit Reason: Quoted text contain spam )

As a solution - disable assets hook for files_after_delete.

Theme © iAndrew 2016 - Forum software by © MyBB