Php 在Codeigniter中的一行中插入多个输入字段值
我有一个表单,其中包含一些输入字段和复选框,我想在一列(行)中插入所有输入值 这是我的表格:Php 在Codeigniter中的一行中插入多个输入字段值,php,mysql,codeigniter,checkbox,Php,Mysql,Codeigniter,Checkbox,我有一个表单,其中包含一些输入字段和复选框,我想在一列(行)中插入所有输入值 这是我的表格: <form action="" method="post"> <label>Built in year</label> <input name="feature[]"> <label>View</label> <input name="feature[]"> 这是我的模型: function f_detail
<form action="" method="post">
<label>Built in year</label>
<input name="feature[]">
<label>View</label>
<input name="feature[]">
这是我的模型:
function f_detail($fvalue){
$this->db->insert('feature',$fvalue);
return $this->db->insert_id();
}
我得到一个错误:
您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以了解在第1行使用接近“0,1,2)值(“内置年份”、“视图”、“停车位”)的正确语法
我的代码有什么问题。任何人请告诉我
在
codeigniter
中使用$this->input->post()
而不是$\u post()
,两者都是等效的
控制器:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
型号:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
在您的模型中,您需要指定列名
,如下所示:
function f_detail($fvalue)
{
$this->db->insert('feature',array('column_name'=>$fvalue));//specify column name
return $this->db->insert_id();
}
在
codeigniter
中使用$this->input->post()
而不是$\u post()
,两者都是等效的
控制器:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
型号:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
在您的模型中,您需要指定列名
,如下所示:
function f_detail($fvalue)
{
$this->db->insert('feature',array('column_name'=>$fvalue));//specify column name
return $this->db->insert_id();
}
您可以使用
内爆
功能在一列中输入多个值
控制器:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
型号:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
您可以使用
内爆
功能在一列中输入多个值
控制器:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
型号:
function create_listing(){
if($this->input->post()){
$feature = $this->input->post('feature');
foreach($feature as $fkey => $fvalue ){
$ids []= $this->Mdata->f_detail($fvalue);//$Ids is array of returned id
}
$this->load->view('form');//load view after database operations
}
function create_listing(){
if($this->input->post()){
$data = array (
'feature' => implode(",", $this->input->post('feature'))
);
$this->Mdata->f_detail($data);
}
else{
$data = array ();
$this->load->view('form', $data);
}
}
function f_detail($data){
$this->db->insert('feature',$data);
return $this->db->insert_id();
}
这不是您应该使用RDBMS的方式。这里有成千上万的问题来自于走这条路的人,他们现在正在犹豫。不要将CSV保存在一列中,在插入查询后放置“echo$this->db->last_query();die;”。它将显示您的查询并检查您的错误。这不是您应该使用RDBMS的方式。这里有成千上万的问题来自于走这条路的人,他们现在正在犹豫。不要将CSV保存在一列中,在插入查询后放置“echo$this->db->last_query();die;”。它将显示您的查询并检查您的错误所在。如果我在模型中应用循环而不是控制器,是否有任何方法是可行的。您需要传递feature array
$feature
,然后在那里使用循环。您是否使用上述答案或任何其他问题解决了它。实际上,我的表单在两个表中插入数据,一个表用于功能,另一个表用于基本信息??这是一个工作,但问题是我的基本信息是插入多次。例如,如果用户检查3个功能,则基本信息也会插入3个重复数据。因此,我希望用户基本信息插入一次,但这不会发生,因为foreach循环是否有任何方法可以在模型中应用循环而不是控制项。您需要传递功能数组$feature
,然后在那里使用循环。是否有您可以使用上述答案或任何其他问题来解决它。实际上,我的表单在两个表中插入数据,一个表用于功能,另一个是基本信息??这是一个工作,但问题是我的基本信息是插入多次。例如,如果用户检查3个功能,则基本信息也会插入3个重复数据。因此,我希望用户基本信息插入一次,但由于foreach循环,这不会发生。我希望将3个字段中的值插入数据库中的单个列,你们能帮我吗?我想把3个字段中的值插入数据库中的一列,你们能帮我吗?