codeigniter中“字段列表”中的未知列'$ data'

时间:2017-11-15 05:14:23

标签: php mysql codeigniter

我试图在我的数据库中插入数据并出现此错误:

错误号码:1054

'字段列表'中的未知列'$ data'

INSERT INTO crud$data)VALUES('')

文件名:C:/AppServ/www/parcial/system/database/DB_driver.php

行号:691

这是我的表格:

 <?php echo form_open('home/save',['class'=>'form-horizontal']); ?>
  <fieldset>



      <label for="exampleInputEmail1">Titulo</label>
    <?php echo form_input(['name'=>'id','class'=>'form-control','placeholder'=>'Titulo', 'value'=>set_value('')]); ?>

      <?php echo form_input(['name'=>'titulo','class'=>'form-control','placeholder'=>'Titulo', 'value'=>set_value('titulo')]); ?>


      <label for="exampleInputEmail1">Resumen</label>
  <?php echo form_input(['name'=>'resumen','class'=>'form-control','placeholder'=>'Titulo', 'value'=>set_value('resumen')]); ?>

      <label for="exampleInputEmail1">Ano</label>
    <?php echo form_input(['name'=>'ano','class'=>'form-control','placeholder'=>'Titulo', 'value'=>set_value('ano')]); ?>

          <label for="exampleInputEmail1">Pais</label>
      <?php echo form_input(['name'=>'pais','class'=>'form-control','placeholder'=>'Titulo', 'value'=>set_value('pais')]); ?>
      <label for="exampleInputEmail1">Protagonista</label>
        <?php echo form_input(['name'=>'progatonista','class'=>'form-control','placeholder'=>'Titulo', 'value'=>set_value('protagonista')]); ?>
  <br>


  <?php echo form_close(); ?>
<?php echo form_submit(['value'=>'Submit', 'class'=>'btn btn-primary']); ?>

这是我保存记录的功能:

  public function save() {

    $data = $this->input->post();
$this->load->model('Crudmodel');
if($this->Crudmodel->saveRecords($data)) {



}
}

这是我要插入的代码:

public function saveRecords($data) {

  return  $this->db->insert('crud','$data');


}

我该怎么办?请帮帮我

4 个答案:

答案 0 :(得分:0)

删除引号,您需要一系列key =&gt;值,这些值会映射到您的表格列

public function saveRecords($data) {

  return  $this->db->insert('crud',$data);


}

答案 1 :(得分:0)

Remove inverted comma from data field in it should be like below
return  $this->db->insert('crud',$data);

答案 2 :(得分:0)

您可以尝试执行此命令:

return  $this->db->insert('crud',$data);

答案 3 :(得分:0)

控制器中的

public function save() {

    $data = $this->input->post();
$this->load->model('Crudmodel');

$data = array (
            'database-fieldname' => $this->input->post('input-fieldname'),
            );

if($this->Crudmodel->saveRecords($data)) {



  }
}