dtd793353 2019-08-08 05:46
浏览 28

列'foto'不能为null

I'm trying to insert a new image into the database, but I got this error. Could someone help me please?

Here is my Controller:

public function tambahfotoproses()
    {
        $variable = 'foto'; //variable name dari form
        $directory = './assets/images/dokter/'; //direktori
        $allowed_file = 'gif|jpg|jpeg|png|JPG|GIF|PNG|JPEG'; //file yang diizinkan dibatasi dengan tanga |
        $upload['detail'] = $this->m_admin->uploadfile($variable,$directory,$allowed_file); //proses dengan modul insertfile
        /* to upload file */
        $filename = $upload['detail']['file_name'];

        if ($filename != "")
        {
            $data = array(
                'foto' => $filename,
                'person_nm' => $this->input->post('person_nm'),
                'pengupload' => $this->input->post('pengupload'),
                'tgl' => $this->input->post('tgl')
            );
            $insert = $this->db->insert('eregister_foto',$data);

        } else {
            $data = array(
                'foto' => $filename,
                'person_nm' => $this->input->post('person_nm'),
                'pengupload' => $this->input->post('pengupload'),
                'tgl' => $this->input->post('tgl')
            );
            $insert = $this->db->insert('eregister_foto',$data);
        }

        redirect('index.php/admin/foto_dr');
    }

public function aksi_upload(){
    //membuat konfigurasi
    $config = [
        'upload_path' => './assets/images/dokter',
        'allowed_types' => 'gif|jpg|jpeg|png|JPG|GIF|PNG|JPEG',
        'max_size' => 1000, 'max_width' => 1000,
        'max_height' => 1000
    ];
    $this->load->library('upload', $config);
    if (!$this->upload->do_upload('foto'))
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('eregister_foto', $error);
    }   else

    {
        $file = $this->upload->data();
        //mengambil data di form
        $data = ['foto' => $file['file_name'],
            'person_nm' => set_value('person_nm'),
            'pengupload' => set_value('pengupload'),
            'tgl' => set_value('tgl')
        ];
        $insert = $this->db->insert('eregister_foto',$data);
        redirect('index.php/admin/foto_dr');
    }
}

I am trying to build with codeigniter, here is my Modals.php I made this modals to change the name of the inputted photo

/AKSI UPLOAD FILE/

function uploadfile($var,$dir,$all){
    $new_name = $this->input->post('person_nm');
    $config2=array(
        'image_library' => 'gd2',
        'upload_path' => $dir."/dokter/", //lokasi gambar akan di simpan
        'allowed_types' => $all, //ekstensi gambar yang boleh di unggah
        'create_thumb' => TRUE,
        'max_size' => '2048', //batas maksimal ukuran gambar
        'file_name' => $new_name
    );

    $this->load->library('upload');
    $this->upload->initialize($config2);
    if ($this->upload->do_upload($var))
    {
        return $this->upload->data();
    }
    else
    {
        return 0;
    }
}

Error Number: 1048

Column 'foto' cannot be null

here is my view.php :

<div class="modal fade" id="tambahdata">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form action="<?php base_url(); ?>tambahfotoproses" method="post" enctype="multipart/form-data">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">Tambah Data Jam Kedatangan</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label>Pilih Dokter</label>
                                <select class="form-control select2" name="person_nm" style="width: 100%;">
                                    <option selected="selected">- Pilih Dokter -</option>
                                    <?php foreach ($xocp_persons as $nama_dokter): ?>
                                        <option value="<?php echo $nama_dokter['person_nm']; ?>"><?php echo $nama_dokter['person_nm']; ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>

                            <input type="text" name="pengupload" value="<?php echo $this->session->userdata("user_nm"); ?>" hidden>
                            <input type="text" name="tgl" value="<?php date_default_timezone_set('Asia/Jakarta'); echo date('Y-m-d h:i:s'); ?>" hidden>

                            <div class="form-group">
                                <label for="exampleInputFile">Upload Foto</label>
                                <input type="file" id="inputfile" name="foto">
                                <script type="text/javascript">
                                    function readURL(input) {
                                        if (input.files && input.files[0]) {
                                            var reader = new FileReader();

                                            reader.onload = function(e) {
                                                $('#blah').attr('src', e.target.result);
                                            }

                                            reader.readAsDataURL(input.files[0]);
                                        }
                                    }

                                    $("#inputfile").change(function() {
                                        readURL(this);
                                    });
                                </script>
                            </div>

                            <div class="form-group">
                                <img id="blah" src="" width="150px">
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-danger pull-left" data-dismiss="modal">Batal</button>
                            <button type="submit" class="btn btn-success">Simpan</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算