无法插入数据库CodeIgniter

时间:2017-05-23 11:26:44

标签: php codeigniter

我的模特

<?php

class Keluhan extends CI_Model {

    var $tabel = 'tb_keluhan';

    function __construct() {
        parent::__construct();
    }

    function GetAllCustomer() {
        $hasil = $this->db->query("SELECT * FROM tb_customer ORDER BY username");
        if ($hasil->num_rows() > 0) {
            foreach ($hasil->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }

    function GetCustomerSession($username) {
        $hasil = $this->db->query("SELECT * FROM tb_customer WHERE username='" . $username . "'");
        if ($hasil->num_rows() > 0) {
            foreach ($hasil->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }

    function InsertFeedback($data) {
        $this->db->insert('tb_keluhan', $data);
        return;
    }

    function InsertRating($data) {
        $this->db->insert('tb_rating', $data);
        return;
    }


    //CRUD
    function insertCustomer($data) {
        $this->db->insert('tb_customer', $data);
        return;
    }



    function get_data_by_id($table, $kode) {
        $this->db->where('id', $kode);
        return $this->db->get($table);
    }

    function updateCustomer($table, $kode, $data) {
        $this->db->where('id', $kode);
        return $this->db->update($table, $data);
    }

    function del_by_id($table, $kode) {
        $this->db->where('id', $kode);
        $this->db->delete($table);
    }

     function GetAllKeluhan() {
        $hasil = $this->db->query("SELECT * FROM tb_keluhan");
        if ($hasil->num_rows() > 0) {
            foreach ($hasil->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }

    function GetAllSudahProses() {
        $hasil = $this->db->query("SELECT * FROM tb_keluhan WHERE status='SELESAI' ORDER BY status");
        if ($hasil->num_rows() > 0) {
            foreach ($hasil->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }

     function GetAllBelumProses() {
        $hasil = $this->db->query("SELECT * FROM tb_keluhan WHERE status='BELUM' ORDER BY status");
        if ($hasil->num_rows() > 0) {
            foreach ($hasil->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }




    //END OF CRUD
}

?>

我的控制器//控制器

public function rateform($username,$id,$name) {

      $rating = $this->input->post('rating');
    $name2 = urldecode($name);
       $data = array
           (
            'id' => $this->input->post('id'),
            'username' => $this->input->post('username'),
           'rating' => $this->input->post('rating')

        );


       $result = $this->login_database->InsertRating($data);
        if ($result == TRUE) {
            $data['message_display'] = 'Registration Successful !';

      } else {
           $data['message_display'] = 'Username already exist!';

       }

帮助我,我无法将数据插入数据库。 $ result al was false,数据没有进入数据库 我不明白错误

1 个答案:

答案 0 :(得分:0)

使用以下代码更改您的控制器功能

我认为您正在调用错误的模型来插入评级

  public function rateform($username,$id,$name) {
    $this->load->Model('Keluhan'); // load your model 
          $rating = $this->input->post('rating');
        $name2 = urldecode($name);
           $data = array
               (
                'id' => $this->input->post('id'),
                'username' => $this->input->post('username'),
               'rating' => $this->input->post('rating')



                );


               $result = $this->Keluhan->InsertRating($data); // change your model name where you want to insert rating
                if ($result == TRUE) {
                    $data['message_display'] = 'Registration Successful !';

              } else {
                   $data['message_display'] = 'Username already exist!';

               }
}