Hello,
Happy New year

please help me senior bro,I can't insert mulityple selected checkbox value into my databse.When i click SUBIT then it show me below error:

*Error Number: 1054

Unknown column '0' in 'field list'

INSERT INTO `tbl_course_offred` (`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `user_id`) VALUES ('1', '2', '3', '4', '89', '5', '22', '106', '133', '11')

Filename: D:\xampp\htdocs\training\system\database\DB_driver.php

Line Number: 330 *

Emphasized Text Here

Here is my form page:

*<form action="<?php echo base_url();?>user_admin_controller/saveCourses" method="post">

<input type="checkbox" name="skill[]" id="skill[]" value="1" /> Accounting 
<input type="checkbox" name="skill[]" id="skill[]" value="2" /> Accounting Short term 
<input type="checkbox" name="skill[]" id="skill[]" value="3" /> Actuarial Courses
<input type="checkbox" name="skill[]" id="skill[]" value="4" /> Advanced Accounting 
<input type="checkbox" name="skill[]" id="skill[]" value="89" /> Advanced Level 
<input type="checkbox" name="skill[]" id="skill[]" value="5" /> Air hostesses Training
<input type="checkbox" name="skill[]" id="skill[]" value="97" /> AME 
<input type="checkbox" name="skill[]" id="skill[]" value="6" /> Athletic
                                    .
                                    .
                                    .
                                    .
<input type="submit" name="submit" value="Submit" class="button"/>
                </form>*

My CI_Controller:

public function saveCourses() {
        $data = $_POST;
        if (isset($_POST['submit'])) {
            $data = $_POST['skill'];   // here 'SKILL' = tabel Field name
            implode(',', $data);

        }
        $data['user_id'] = $this->session->userdata('user_id');
        $this->user_admin_model->saveInstituteOfferdCourse($data);  //model function_name: saveInstituteOfferdCourse
        redirect("user_admin_controller/messageCoursesskill");
    }

My CI_MODEL:

public function saveInstituteOfferdCourse($data) {
        $this->db->insert('tbl_course_offred',$data);
     //  return $this->db->affected_rows();

    }

please help me how can i solve this problem?

I have another help like:

Q. How can i display data without ',' comma view page ?

please please help me senior..

Regards

Recommended Answers

All 2 Replies

INSERT INTO tbl_course_offred (0, 1, 2, 3, 4, 5, 6, 7, 8, user_id) VALUES ('1', '2', '3', '4', '89', '5', '22', '106', '133', '11')

The values between the first parenthesis should be the column names. Not sure where these are coming from, but those columns aren't in your table.

Member Avatar for diafol

It looks as if you've got a strange schema. You can use bitwise operators and addition to retrieve and store this type of data.

$skills = array_sum($_POST['skill']);

However, your skill[] values would need to be 1,2,4,8,16 etc.

You could then search with bitwise oeprators:

SELECT ... FROM ... WHERE `skills` & 2

Just a thought.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.