【问题标题】:inserting text area data to database将文本区域数据插入数据库
【发布时间】:2013-01-23 10:04:45
【问题描述】:

我正在尝试在文本字段中插入一些文本,有两个字段一个是票,它工作正常,另一方面报告没有正确插入到 sql。这是我的视图代码

<td><input type='text' id='ticket' name='ticket'/></td>
<td><textarea id='report' name='report'>enter text report</textarea></t

这是我的控制器

function testUpload(){
    $data=array(
        'ticket'=>$this->input->post('ticket'),
        'report'=>$report=$this->input->post('repost')
    );
    $this->load->model('patient_model');
    $this->patient_model->insertReport($data);
}

这是我的模型

function insertReport($data){
    $this->db->insert('report',$data);
}

【问题讨论】:

  • $this-&gt;input-&gt;post('repost').... 转发?或report?

标签: php codeigniter textarea


【解决方案1】:

试试下面的代码,把repost改成report

function testUpload(){
        $data=array(
        'ticket'=>$this->input->post('ticket'),
        'report'=>$report=$this->input->post('report')
        );

    $this->load->model('patient_model');
    $this->patient_model->insertReport($data);
}

编辑:-

好像你已经编辑了你的问题,

最初是'report'=&gt;$report=$this-&gt;input-&gt;post('tr')

现在你有零钱'report'=&gt;$report=$this-&gt;input-&gt;post('repost')

都错了……

【讨论】:

  • 这似乎是一场找不同的游戏……
  • @Quentin 你是对的,但最初他提到了post('report')' as post('tr')`
  • 描述变化通常比重写代码更有帮助——尤其是当它像'repost'/'report'这样细微的变化时
  • 我明白@Quentin .. 下次我会确保 :)
【解决方案2】:

你有name='report'$this-&gt;input-&gt;post('repost')

在引用您的字段时,您需要避免拼写错误。

【讨论】:

    【解决方案3】:

    请将repost 更改为report

    因为你的文本区域名称是报告

    因此,您的控制器应该如下所示...

    function testUpload(){
        $data=array(
            'ticket'=>$this->input->post('ticket'),
            'report'=>$report=$this->input->post('report')
        );
        $this->load->model('patient_model');
        $this->patient_model->insertReport($data);
    }
    

    【讨论】:

      【解决方案4】:

      试试这个。

      function testUpload(){
          $data=array(
              'ticket'=>$this->input->post('ticket'),
              'report'=>$this->input->post('report')
          );
          $this->load->model('patient_model');
          $this->patient_model->insertReport($data);
      }
      

      并且您必须确定表格报告中必须存在字段报告。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-29
        • 2023-04-02
        • 2017-09-27
        • 2014-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多