【发布时间】:2019-08-25 12:28:03
【问题描述】:
我有一个包含一些输入字段和复选框的表单,我想将所有输入值插入一列(行)中。
这是我的表格:
<form action="" method="post">
<label>Built in year</label>
<input name="feature[]">
<label>View</label>
<input name="feature[]">
这是我的控制器:
function create_listing(){
$this->load->view('form');
if($_POST){
$feature = array ( 'feature' => $_POST['feature'] );
foreach($feature as $fkey => $fvalue ){
$this->Mdata->f_detail($fvalue);
}
}
这是我的模型:
function f_detail($fvalue){
$this->db->insert('feature',$fvalue);
return $this->db->insert_id();
}
我收到一个错误:
您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的“0,1,2) VALUES ('build in year', 'view', 'parking space')' 附近使用的正确语法
INSERT INTO `feature` (0, 1, 2) VALUES ('build in year', 'view', 'parking space')
我的代码有什么问题。有谁请告诉我。
问候
【问题讨论】:
-
这不是您应该使用 RDBMS 的方式。走这条路的人提出了数千个问题,现在正在努力解决不要在列中保存 CSV stackoverflow.com/questions/41304945/… stackoverflow.com/questions/41215624/…
-
put "echo $this->db->last_query();die;"在插入查询之后。它将显示您的查询并检查您出错的地方。
标签: php mysql codeigniter checkbox