dongmangsha7354 2013-09-24 19:20
浏览 26
已采纳

使用codeigniter更新/更改数据库中的值

Iam developing using codeIgniter and I have managed to simply post a id number and phone number into the a table named "offers" both fields are INT, however when i try update a phone number corresponding to a specific id I keep getting the following error

Unknown column 'mysubmit' in 'field list'

UPDATE offers SET phneNum = '078444', mysubmit = 'Submit Form' WHERE idNum = '12'

Filename: C:\xampp\htdocs\project\system\database\DB_driver.php

I have listed my controller , model and view below

newOffer/controller

     class newOffer extends CI_Controller {
  function addOffer() {
 //if the form is submitted           
  $this->load->view("check");
 $this->load->model("offer_model");
   if ($this->input->post('mysubmit')) {

       $this->offer_model->entry_insert();
            }

    }
   function updateOffer (){
    $this->load->view("check");
 $this->load->model("offer_model");
 if ($this->input->post('mysubmit')) {
    // $this->offer_model->upddata();
  $this->offer_model->upddata($this->input->post());
   }


  }
 }
 ?>

offer_model

  class offer_model extends CI_Model{
   public function entry_insert(){
     $data = array(
       'idNum' => $this->input->post('idNum'),
        'phneNum' => $this->input->post('phneNum'),

    );

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

}
 public function upddata($data) {
             $data=array();

         $idNum = $data['idNum'];
    $data=$this->input->post(); //get all post value to data array

    unset($data['idNum']); // unset unnecessary values 
   $this->db->where('idNum', $idNum)->update('offers' ,$data);
   return true;
}



}


 ?>

The view // Please enter details for your new offer

        <label for="ID Number">ID Number:  <span class="required">*</span></label>
        <input type="text" name="idNum" id="idNum" placeholder="Please enter ID   Number/>
        <label for="phone Number">Phone Number:</label>
       <input type="text" name="phneNum" id="phneNum   " placeholder="Please enter phone Number"/>

         <fieldset class="submit_field">
          <?php echo form_submit('mysubmit', 'Submit Form'); ?>
       </fieldset>

       </div><!-- end of form div -->
    ?>
  • 写回答

3条回答 默认 最新

  • dongyu8664 2013-09-24 19:47
    关注
    public function upddata($data) {
    
                 $idNum = $data['idNum'];
    
                 $offers_data = array("phneNum" => $data['phneNum']);
    
                 unset($data['idNum']); // unset unnecessary values 
                 $this->db->where('idNum', $idNum)->update('offers' ,$offers_data );
                 return true;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记