Welcome Guest, Not a member yet? Register   Sign In
Can't get information to insert into database

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:
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
            // 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);
            // Create file name array for database entry
            $image_data = $this->upload->data();
            // 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;
            // data for database insert
                $data['image'] = 'img/'.$image_data['file_name'];
            // config thumbnail
            $configThumb['source_image'] = $image_data['full_path'];
            $configThumb['new_image'] = './uploads/thumbs/';
            $configThumb['maintain_ratio'] = TRUE;
            $configThumb['height'] = 97;
            $configThumb['width'] = 144;
            // thumbnail data for database insert
                $data['thumbnail'] = 'thumbs/'.$image_data['file_name'];
        // insert data
        $this->db->insert('product', $data);
View Code:
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:
function create_equipment()
        if ($this->input->post('name'))
            $this->session->set_flashdata('message', 'Product Added');
            redirect('admin/equipment', 'refresh');
            $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.

First things to test would be what's in your array before you do the Insert - make sure all the correct data is there.

Next thing would be to check the last query using:


Also, do you have php error reporting on?

You can use the profiler to narrow down where the problem is, if you get an output from the profiler then you will know that you have an sql error or something wrong with the upload function.

If you don't get any output then your controller has a problem which i don't think so but you never know.

Also I see that you're using an SQL time stamp which is 2011-05-10 02:02:40 am or something you might be getting an error there SQL hates it when the time stamp is not in the right format.

That is why more experience programmers use time to keep track of time meaning when was it inserted, updated and so on... Best thing of all when using operators it makes it much easier to work with and you can have as many time tracker fields as you like, like and expire feature date instead of SQLs that only allows you to have 1 time stamp field per table. By the way when you use time you use an int field and when you want to return a date you can use the date() function just add your format and then the the return unix time stamp. SO keep that in mind even if that is not the error.

Theme © iAndrew 2016 - Forum software by © MyBB