2017-05-23 86 views
-6

我的模型廣東話插入到數據庫笨

<?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 
} 

?> 

我控制器// CONTROLER

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!'; 

     } 

幫我,我不能插入數據到數據庫中。 $結果alwas錯誤和數據沒有進入到數據庫 我不與錯誤

+0

顯示所有代碼,$ data的錯誤和var_dump – calexandre

+0

在控制器構造函數中添加此行。 '$ this-> load-> model('login_database');' –

+0

請閱讀如何在此處編輯器中對代碼進行格式化https://meta.stackexchange.com/questions/22186/how-do-i-format-我的代碼塊 – user4419336

回答

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!'; 

       } 
} 
您的控制器功能