[eluser]mikegeorgeff[/eluser]
I have a small CMS where my customer can add products to their site. When the data gets submitted it goes to a blank screen and the information does not insert.
Model Code:
Code:
function addProduct()
{
$now = date("Y-m-d H:i:s");
$data = array(
'name' => $this->input->post('name'),
'desc' => $this->input->post('desc'),
'category_id' => $this->input->post('category_id'),
'featured' => $this->input->post('featured'),
'date' => $now
);
if($_FILES)
{
// Config the upload
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '2048';
$config['remove_spaces'] = TRUE;
$config['overwrite'] = FALSE;
// Do the upload
$this->load->library('upload', $config);
if(!$this->upload->do_upload('image'))
{
$this->upload->display_errors();
exit();
}
// Create file name array for database entry
$image_data = $this->upload->data();
$this->load->library('image_lib');
// Config image size for Prod details page
$config['source_image'] = $image_data['full_path'];
$config['new_image'] = './uploads/img/';
$config['maintain_ratio'] = TRUE;
$config['height'] = 157;
$config['width'] = 204;
$this->image_lib->initialize($config);
if(!$this->image_lib->resize())
{
$this->image_lib->display_errors();
exit();
}
// data for database insert
if($image_data['file_name'])
{
$data['image'] = 'img/'.$image_data['file_name'];
}
$this->image_lib->clear();
// config thumbnail
$configThumb['source_image'] = $image_data['full_path'];
$configThumb['new_image'] = './uploads/thumbs/';
$configThumb['maintain_ratio'] = TRUE;
$configThumb['height'] = 97;
$configThumb['width'] = 144;
$this->image_lib->initialize($configThumb);
if(!$this->image_lib->resize())
{
$this->image_lib->display_errors();
exit();
}
// thumbnail data for database insert
if($image_data['file_name'])
{
$data['thumbnail'] = 'thumbs/'.$image_data['file_name'];
}
}
// insert data
$this->db->insert('product', $data);
}
View Code:
Code:
<?php
echo form_open_multipart('admin/create_equipment');
echo "<p><label>Name</label><br />";
$data = array('name' => 'name', 'id' => 'name', 'size' => 25);
echo form_input($data) ."</p>";
echo "<p><label>Category</label><br />";
echo form_dropdown('category_id', $categories) ."</p>";
echo "<p><label>Description</label><br />";
$data = array('name' => 'desc', 'id' => 'desc', 'rows' => 5, 'cols' => '40');
echo form_textarea($data) ."</p>";
echo "<p><label>Image</label><br />";
$data = array('name' => 'image', 'id' => 'image');
echo form_upload($data) ."</p>";
echo "<p><label>Featured?</label><br />";
$options = array('false' => 'false', 'true' => 'true');
echo form_dropdown('featured', $options) ."</p>";
echo form_submit('submit', 'Add Product');
echo form_close();
?>
Controller Code:
Code:
function create_equipment()
{
if ($this->input->post('name'))
{
$this->MProducts->addProduct();
$this->session->set_flashdata('message', 'Product Added');
redirect('admin/equipment', 'refresh');
}else{
$data['title'] = 'Add Product';
$data['main'] = 'admin/new_product';
$data['categories'] = $this->MCats->getCategoriesDropDown();
$this->load->view('admin/template', $data);
}
}
I can't see what the issue is.