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

标签 php mysql codeigniter

新年快乐

请大哥帮帮我,我无法将多个选中的复选框值插入到我的数据库中。当我单击 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();

    }

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

我还有另一个帮助,例如:

问。如何在没有“,”逗号 View 页面的情况下显示数据?

请高人帮帮我..

问候,

最佳答案

您的代码中有很多缺陷。

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

2) 你没有在插入查询中提到表字段名..

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

关于php - 错误显示在 codeigniter 中插入多个选中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14154259/

相关文章:

php - 计算当天剩余分钟数

mysql - 如何使用 -initWithContentsOfURL 获取 MySQL 查询结果?

php - 语法错误或访问冲突 : 1064 ' brandname

javascript - 如何获取动态追加复选框列表中的值

PHP post_max_size 覆盖upload_max_filesize

php - 如何修复 sendmail.php 不起作用?

具有多个选择的 php sql 不起作用

mysql - 连接表和循环

php - 从 mysql 查询转换为 mssql 查询

php - 通过 PHP 更改 URL