Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文本框插入+;更新Codeigniter中的不同选项卡?_Php_Mysql_Codeigniter - Fatal编程技术网

Php 文本框插入+;更新Codeigniter中的不同选项卡?

Php 文本框插入+;更新Codeigniter中的不同选项卡?,php,mysql,codeigniter,Php,Mysql,Codeigniter,问题:如何在CodeIgniter 我的数据库结构 t_mynetpoin |id_mynetpoin |tot_poin |last_modified| nim | |id_log_mynetpoin | id_paket_redeem | id_mynetpoin | status | total | time | keterangan | t_log_mynetpoin |id_mynetpoin |tot_poin |last_modified| nim | |id_log_myn

问题:如何在
CodeIgniter

我的数据库结构

t_mynetpoin

|id_mynetpoin |tot_poin |last_modified| nim |
|id_log_mynetpoin | id_paket_redeem | id_mynetpoin | status | total | time | keterangan |
t_log_mynetpoin

|id_mynetpoin |tot_poin |last_modified| nim |
|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>
$data
应根据要修改的表而有所不同。 这里有什么奇怪的地方:

$query = $this->Super_Model->update('t_mynetpoin','id_mynetpoin = '.$id,$post);
您必须从
$post
数据构造
$data
,而不是将原始
$post
提供给更新方法

或者,如果您没有更新正确的表--
t\u mynetpoin
而不是
t\u log\u 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,...

我找到了答案XD,我使用数组来修复

我的控制器已编辑

public function do_edit($id){
    $post = $this->input->post(NULL, FALSE);

    $id_paket_redeem = "2"; 
    $status = "Tambah"; 
    $log = array(
        "id_paket_redeem"=>$id_paket_redeem,
        "id_mynet_poin"=>$id,
        "status"=>$status,
        "total"=>$post['tot_poin'],
        "keterangan"=>$post['keterangan']
    );

    $this->Super_Model->insert('t_log_mynetpoin',$log);


    $now = date('Y-m-d');
    $post['last_modified'] = $now;

    $up = array(
        "tot_poin"=>$post['tot_poin'],
        "last_modified"=>$post['last_modified']
    );
    $query = $this->Super_Model->update('t_mynetpoin','id_mynetpoin = '.$id,$up);

    if($query==1){
        $this->session->set_flashdata('success', 'User berhasil di edit!');
        redirect("super_admin/Coin");
    }else{
        $this->session->set_flashdata('error', 'User gagal di edit!');
        redirect("super_admin/Coin");
    }
}

嗨,irfanhans,你能把你的错误粘贴成格式化的文本而不是图像吗?如果其他人也得到同样的结果,这将非常有用。我复制了一个错误代码。看起来您的数据库不知道
keteragan
列。事实上,表t|u mynetpoin只有您所说的列:
|id|u mynetpoin | tot|u poin | last|u modified | nim |
。您正在更新表
t|u mynetpoin
,该表中没有名为
ketrangan
的列
ketrangan