CodeIgniter Insert查询使用0值进行额外输入

时间:2015-11-14 06:02:41

标签: php mysql codeigniter

当我尝试插入一些值时,MySQL会显示双重输入。第一个条目是正确的,但第二个条目只包含零。请帮帮我......

enter image description here

我的控制器代码在这里:

$config['upload_path'] = './img/trainees/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']        = '200';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
            $this->load->library('upload', $config);
            $imgname ='';
            if($this->upload->do_upload())
             {
       $data = $this->upload->data();
       $imgname = $data['raw_name'].$data['file_ext'];
      }

以上代码用于上传控制器中的图像..  剩余代码:

           $this->load->model('newmodel');

            $this->newmodel->NAME = $this->input->post("name");
            $this->newmodel->AGE = $this->input->post("age");
            $this->newmodel->PLACE = $this->input->post("place");
            $this->newmodel->ADDRESS = $this->input->post("address");
            $this->newmodel->PHONE = $this->input->post("phone");
            $this->newmodel->MAIL = $this->input->post("email");
            $this->newmodel->QUALI = $this->input->post("qualification");
            $this->newmodel->OCCUP = $this->input->post("occupation");
            $this->newmodel->MILMAID = $this->input->post("memberID");
            $this->newmodel->COURSE = $this->input->post("course");
            $this->newmodel->CENTRE  = $this->input->post("centre");
            $this->newmodel->REGDATE = date('d/m/Y');
            $this->newmodel->IMGNAME= $imgname;


            $mydata = $this->newmodel->insertuserdata();        

        $data = array(
    'name' => $this->newmodel->NAME,
    'age' => $this->newmodel->AGE,
            'place' => $this->newmodel->PLACE,
            'address' => $this->newmodel->ADDRESS,
            'phone' => $this->newmodel->PHONE,
            'email' => $this->newmodel->MAIL,
            'quali' => $this->newmodel->QUALI,
            'occup' => $this->newmodel->OCCUP,

            'milmaid' => $this->newmodel->MILMAID,
            'course' => $this->newmodel->COURSE,
            'centre' => $this->newmodel->CENTRE,
            'regdate' => $this->newmodel->REGDATE,
            'imgname' => $this->newmodel->IMGNAME,
               );
    $this->load->helper('url');     
        $this->load->view('users/admitcard',$data);

我的模型代码看起来像这样:

var $NAME = '';        
    var $AGE = 0;
    var $PLACE = '';
    var $ADDRESS = '';
    var $PHONE = 0;
    var $MAIL = '';
    var $QUALI = '';
    var $OCCUP = '';
    var $MILMAID = '';
    var $COURSE = '';
    var $CENTRE = '';
    var $REGDATE = '';
    var $IMGNAME ='';
public function insertuserdata(){


    $this->load->database();
    $datas = array(        
 'Tname' => $this->NAME,
 'Tage' => $this->AGE,
 'Tplace' => $this->PLACE,
 'TAddres' => $this->ADDRESS,
 'Tph' => $this->PHONE,
 'Tmail' => $this->MAIL,
 'Tqualification' => $this->QUALI,
 'Toccupation' => $this->OCCUP,
 'TmilmaMemb' => $this->MILMAID,
 'Tcourse' => $this->COURSE,
 'Tcentre' => $this->CENTRE,
 'regDate' => $this->REGDATE
  );
$this->db->insert('tbl_trainers', $datas);

1 个答案:

答案 0 :(得分:0)

在您的模型上试用此代码

public function insertuserdata(){


    $this->load->database();

    $datas = array( 
     'Tname' => $this->input->post("name"),
     'Tage' => $this->input->post("age"),
     'Tplace' => $this->input->post("place"),
     'TAddres' => $this->input->post("address"),
     'Tph' => $this->input->post("phone"),
     'Tmail' => $this->input->post("email"),
     'Tqualification' => $this->input->post("qualification"),
     'Toccupation' => $this->input->post("occupation"),
     'TmilmaMemb' => $this->input->post("memberID"),
     'Tcourse' => $this->input->post("course"),
     'Tcentre' => $this->input->post("centre"),
     'regDate' => date('d/m/Y')
      );
    $this->db->insert('tbl_trainers', $datas);

}   

只需在控制器上调用此模型即可。现在您的控制器看起来像这样 -

public function yourMethod(){

      $this->load->model('newmodel');
      $this->newmodel->insertuserdata();

     # And your rest code here...
}