gpt4 book ai didi

php - CodeIgniter 插入查询使用 0 值进行额外输入

转载 作者:行者123 更新时间:2023-11-29 21:50:24 26 4
gpt4 key购买 nike

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

enter image description here

我的 Controller 代码在这里:

$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'];
}

以上代码用于在 Controller 中上传图像。 剩余代码:

           $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);

最佳答案

在您的模型上尝试此代码

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);

}

只需在 Controller 上调用此模型即可。现在你的 Controller 看起来像这样 -

public function yourMethod(){

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

# And your rest code here...
}

关于php - CodeIgniter 插入查询使用 0 值进行额外输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33705624/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com