问题:如何插入&在TextBox
CodeIgniter
更新到不同的表格
我的数据库结构
t_mynetpoin
|id_mynetpoin |tot_poin |last_modified| nim |
t_log_mynetpoin
|id_log_mynetpoin | id_paket_redeem | id_mynetpoin | status | total | time | keterangan |
我的模特
public function get($tabel='',$where='',$order='',$limit='',$from=''){
if (!empty($where)) $this->db->where($where);
if (!empty($order)) $this->db->order_by($order);
$query = $this->db->get($tabel,$limit,$from);
if ($query){
return $query->result();
}
else {
return array();
}
public function insert($tabel,$data){
$query = $this->db->insert($tabel,$data);
if($query) return 1;
else return 0;
}
public function update($tabel,$where,$data){
$this->db->where($where);
$query = $this->db->update($tabel,$data);
if ($query) {
return 1;
}else{
return 0 ;
}
}
我的控制器
public function do_edit($id){
$post = $this->input->post(NULL, FALSE);
$now = date('Y-m-d');
$post['last_modified'] = $now;
$query = $this->Super_Model->update('t_mynetpoin','id_mynetpoin = '.$id,$post);
$idpr = "2";
$sts= "tambah";
$total = $post['tot_poin'];
$post_tot['total'] = $total;
$ket = $post['keterangan'];
$post_ket['keterangan'] = $ket;
$this->Super_Model->query('INSERT INTO t_log_mynetpoin (id_paket_redeem, id_mynet_poin, status, total, keterangan) VALUES ($idpr,$id,$sts,$post_tot,$post_ket);');
if($query==1){
$this->session->set_flashdata('success', 'User berhasil di edit!');
redirect("super_admin/User");
}else{
$this->session->set_flashdata('error', 'User gagal di edit!');
redirect("super_admin/User/add");
}
}
我的观点
<form class="form-horizontal" method="post" enctype="multipart/form-data" action="<?php echo site_url("$url")?>">
<p>Masukan Poin yang akan di tambah</p>
<div style="margin-bottom: 10px;"><?php echo form_dropdown("nim", $ambil_nim,@$nim, 'class="form-control" id="nim" disabled="disabled"'); ?></div>
<div><input class="form-control col-sm-10" name = "tot_poin" type="text" value = "<?php echo $tpn?>" style="margin-bottom: 10px;"/></div>
<div><textarea class="form-control col-sm-10" name="keterangan" placeholder="Keterangan menambahkan poin" style="margin-top: 0px;margin-bottom: 0px;height: 100px;"></textarea></div>
</div>
<div class="modal-footer" style="margin-top: 150px;">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Cancel</button>
<button type="submit" class="btn btn-primary btn-raised"><i class="fa fa-check"></i> Submit</button>
</div>
</form>
错误
A Database Error Occurred
Error Number: 1054
Unknown column 'keterangan' in 'field list'
UPDATE `t_mynetpoin` SET `tot_poin` = '8000', `keterangan` = 'hv', `last_modified` = '2016-05-25' WHERE `id_mynetpoin` = 1
Filename: E:/xampp/htdocs/mynet/application/models/Super_Model.php
Line Number: 64
答案 0 :(得分:1)
$data
应根据您要修改的表格而有所不同。这看起来很奇怪:
$query = $this->Super_Model->update('t_mynetpoin','id_mynetpoin = '.$id,$post);
您必须从$data
数据构建$post
,而不是将原始$post
提供给您的更新方法。
如果您未更新右表 - t_mynetpoin
而不是 t_log_mynetpoin
,您可以尝试:
$query = $this->Super_Model->update('t_log_mynetpoin','id_mynetpoin = '.$id,$post);
考虑在两种情况下编写完整查询:
$query = $this->Super_Model->update('t_mynetpoin','id_mynetpoin = '.$id,$post);
因此成为:
$this->Super_Model->query('UPDATE t_mynetpoin SET tot_poin = $idpr,...
答案 1 :(得分:1)
我找到答案XD,我用数组来修复......
我的控制器已编辑
access_token