如何解决错误编号:1048'photo_pict'列不能为null?

时间:2019-05-29 09:16:38

标签: php html codeigniter-3

我收到此错误:

A Database Error Occurred
Error Number: 1048

Column 'photo_pict' cannot be null

    INSERT INTO `tester` (`photo_pict`, `press_pict`, `name_pict`) VALUES (NULL, NULL, NULL)

Filename: C:/xampp/htdocs/pretest/system/database/DB_driver.php

Line Number: 691

我正在使用CodeIgniter,并且是初学者。

我正在制作一个注册表,我所要做的只是将输入从注册表中保存到数据库中。但是除了用于将照片保存到数据库的数据以外,所有数据都已保存到数据库中。

代码在这里显示

型号:

function insert($data){
     $data = array(
        'first_name' => $data['first_name'],
        'last_name' => $data['last_name'],
        'birthDate' => $data['birthDate'],
        'gender' => $data['gender'],
        'posisi' => $data['posisi'],
        'media_name' => $data['media_name'],
        'media_region' => $data['media_region'],
        'media_ctgry' => $data['media_ctgry'],
        'company_addrss' => $data['company_addrss'],
        'website' => $data['website'],
        'editor_email' => $data['editor_email'],
        'office_phone' => $data['office_phone'],
        'office_fax' => $data['office_fax'],
        'personal_email' => $data['personal_email'],
        'phone_number' => $data['phone_number'],
        'working_email' => $data['working_email']
    );
    $this->db->insert('tester', $data);
}

    function upload($data){
     $gambar = array(
    'photo_pict'=> $data['photo_pict'],
    'press_pict'=> $data['press_pict'],
    'name_pict'=> $data['name_pict']
    );
    $this->db->insert('tester', $gambar);
}

    function proses_regist(){
    return $this->db->insert('tester', $data);
    }
}

我的控制器:

public function __construct(){
    parent :: __construct();
    $this->load->model("Model_regist");
    $this->load->helper(array('url','form'));
}

public function index(){
    $this->load->view('home');
}

function register(){
    $gambar = array(
    'press_pict'=>$this->upload->data("photo_pict"),
    'photo_pict'=>$this->upload->data("press_pict"),
    'name_pict'=>$this->upload->data("name_pict")
    );

    $data = array(
        'first_name' => $this->input->post("first_name"),
        'last_name' => $this->input->post("last_name"),
        'birthDate' => $this->input->post("birthDate"),
        'gender' => $this->input->post("gender"),
        'posisi' => $this->input->post("posisi"),
        'media_name' => $this->input->post("media_name"),
        'media_region' => $this->input->post("media_region"),
        'media_ctgry' => $this->input->post("media_ctgry"),
        'company_addrss' => $this->input->post("company_addrss"),
        'website' => $this->input->post("website"),
        'editor_email' => $this->input->post("editor_email"),
        'office_phone' => $this->input->post("office_phone"),
        'office_fax' => $this->input->post("office_fax"),
        'personal_email' => $this->input->post("personal_email"),
        'phone_number' => $this->input->post("phone_number"),
        'working_email' => $this->input->post("working_email")
);
    $this->Model_regist->insert($data);
    $this->Model_regist->upload($gambar);
    $this->index();
}

private function uploadImage(){
    $config['upload_path']          = './gambar/';
    $config['allowed_types']        = 'gif|jpg|png';
    $config['file_name']            = $this->product_id;
    $config['max_size']             = 100;
    $config['max_width']            = 1024;
    $config['max_height']           = 768;
    $config['overwrite']             = true;
    $nama_file                   = "gambar_".time();
    $config['file_name']             = $nama_file;
    $this->load->library('upload', $config);

if( ! $this->upload->do_upload('berkas')){
    $error = array('error' => $this->upload->display_errors());
}else{
    $this->upload->data();
}
    $this->Model_regist->upload($gambar);
    $this->Model_regist->insert($data);
    $this->index();

}

我希望选择的照片可以保存在数据库中,也可以保存在我之前制作的文件中。文件名为gambar。

0 个答案:

没有答案