[eluser]zyklon[/eluser]
Can someone tell me why this simple piece of code don't work?It's a form with an image upload.I made a function for the image upload,it's working separately but when i make
$this->upload_photos(); doesn't work.
function upload_photos()
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
}
else
{
$upload_data = $this->upload->data();
$post_image = $upload_data["file_name"];
return $post_image ;
}
public function add_sponsors()
{
$view_data["action"] = "add_sponsors";
$this->load->helper(array('form', 'url'));
$this->load->model('Admin_model','admin');
$view_data['internal_error']="";
$this->load->library('validation');
$rules["name"] = "trim|required";
$rules["description"] = "trim|required";
$rules["website"] = "trim";
$this->validation->set_rules($rules);
$fields["name"] = "Nume";
$fields["description"] = "Descriere";
$fields["website"] = "Website(without http://)";
$this->validation->set_fields($fields);
$this->validation->set_message("required","Nu ati completat campul %s");
$this->validation->set_error_delimiters('<br>', '');
if($this->validation->run() == FALSE)
{
$this->load->view('admin/front/admin_front_view', $view_data);
}
else
{
$result_sponsors = $this->admin->check_sponsors("sponsors",$this->input->post('name','TRUE'));
if($result_sponsors == TRUE)
{
$name = $this->input->post('name','TRUE');
$description = $this->input->post('description','TRUE');
$website = $this->input->post('website','TRUE');
$post_image = $this->upload_photos();
$result_create_sponsors = $this->admin->create_sponsors("sponsors",$name,$description,$website,$post_image);
if($result_create_sponsors == TRUE)
{
header("Location: ". $this->config->item('base_url')."index.php/admin/view_sponsors");
}
else
{
$view_data['internal_error'] = 'Inregistrarea nu a putut fi facuta';
$this->load->view('admin/front/admin_front_view', $view_data);
}
}
else
{
$view_data['internal_error']='Acest sponsor deja exista';
$this->load->view('admin/front/admin_front_view', $view_data);
}
}
}
The error i get is:
Column 'file' cannot be null
INSERT INTO gl_sponsors (id, name, description, website, file) VALUES ('', 'fdgf', 'dfgdsg', '', NULL)