我尝试了以下一些代码,并收到错误消息
错误号:1048 列brand_logo不能为空 插入到tbl_brand(品牌名称,brand_logo)值(“ Incoe”,NULL)“
请帮助我找出错误(对不起我的英语不好)
这是型号:
public function add_brand_model($brand_logo){
$data['brand_name'] = $this->input->post('brand_name',true);
$data['brand_logo'] = $brand_logo;
$this->db->insert('tbl_brand',$data);
}
视图:
<div class="form-group">
<label>Upload Brand Logo</label>
<input type="file" name="brand_logo">
</div>
和控制器:
public function add_brand_form(){
$data['main_content'] = $this->load->view('back/add_brand','',true);
$this->load->view('back/adminpanel',$data);
}
public function save_brand(){
$brand_logo= $this->upload_brand_logo();
$this->form_validation->set_rules('brand_name','Brand Name','required|min_length[2]');
if($this->form_validation->run()){
$this->BrandModel->add_brand_model($brand_logo);
$this->session->set_flashdata("flsh_msg","<font class='success'>Brand Added Successfully</font>");
redirect('brand-list');
}else{
$this->add_brand_form();
}
}
private function upload_brand_logo(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'png|gif|jpg|jpeg';
$config['max_size'] = 1000;//kb
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if($this->upload->do_upload('brand_logo')){
$data = $this->upload->data();
$image_path = "uploads/$data[file_name]";
return $image_path;
}else{
$error = $this->upload->display_errors();
$this->session->set_userdata('error_image',$error);
}
}
答案 0 :(得分:0)
尝试一下
if($this->upload->do_upload('brand_logo')){
$data = $this->upload->data();
$image_path = "uploads/".$data[file_name]; //Change
return $image_path;
}else{
$error = $this->upload->display_errors();
$this->session->set_userdata('error_image',$error);
return false; //New addition
}
OR
$image_path = '';
if($this->upload->do_upload('brand_logo')){
$data = $this->upload->data();
$image_path = "uploads/".$data[file_name]; //Change
}else{
$error = $this->upload->display_errors();
$this->session->set_userdata('error_image',$error);
}
return $image_path; //return here only one time