Я получил эту ошибку:
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.