错误显示在codeigniter中插入多个选中的值

时间:2013-01-04 09:19:30

标签: php mysql codeigniter

新年快乐

请帮助我高级兄弟,我不能将mulityple选中的复选框值插入我的数据库。当我点击SUBIT然后它显示我下面的错误:

*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 *

强调文字

这是我的表单页面:

*<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>*

我的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");
    }

我的CI_MODEL:

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

    }

请帮助我如何解决这个问题?

我还有其他帮助:

问。如何在没有','逗号查看页面的情况下显示数据?

请帮助我高级..

此致

2 个答案:

答案 0 :(得分:2)

您的代码中存在很多缺陷。

1)首先,不要将元素ID保留为数组..给出一些唯一的ID

2)您没有在插入查询中提及表字段名称。

3)你犯了一个错误。您将元素名称视为表字段名称..

答案 1 :(得分:0)

您的表格中没有column作为0。再次检查表格结构

如查询所示 - 您的表格tbl_course_offred columns[0,1,2,3,4,5,6,7,8,user_id]

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')

但从给定的错误中可以清楚地看出,没有这样的专栏。

粘贴以下命令的输出(mysql终端)

  

DESCRIBE tbl_course_offred