Welcome Guest, Not a member yet? Register   Sign In
Capture combo box value
#1

Hello,

I wonder how to capture combo box value into databases?


images_model.php

    function add()
    {    

        $data = array('img_name' => $this->upload->data('file_name'),
                      'img_ctg' => $this->input->post('img_ctg')
                );

        $this->db->insert($this->table, $data);
    }


add_image.php

          <form action="<?php echo site_url("add_image"); ?>" method="POST" enctype="multipart/form-data">

                    <br><br>

                     Image category:<br><br>
                     <select name="img_ctg">
                        <option value="services">services</option>
                        <option value="projects">projects</option>
                        <option value="clients">clients</option>
                        <option value="shop">shop</option>
                     </select>

                    <br><br>

                    <p>Upload Image:<br><br>
                    <input class="form-control" name="up_image" multiple="" accept="image/png,image/jpeg" type="file">
                    <br><br>
                    <input class="edit" type="submit" value="Upload">
                   
                   </p>

                 </form>

Error Number: 1048
Column 'img_ctg' cannot be null
INSERT INTO `images` (`img_name`, `img_ctg`) VALUES ('Bali-Trip2.jpg', NULL)
Filename: C:/xampp/htdocs/coolcicms/system/database/DB_driver.php
Line Number: 691

I must have coded this line:

  'img_ctg' => $this->input->post('img_ctg')

incorrectly.

How to fix this prob?
" If I looks more intelligence please increase my reputation."
Reply
#2

Process input ($this->upload... and $this->input...) in your controller, not your model. Pass the values to the model from the controller.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB