2016-06-24 3 views
0

제출 된 양식을 사용하여 데이터를 삽입하려고합니다. 데이터가 데이터베이스에 올바르게 입력되었지만 모바일 용 API도 사용하고 있습니다. is_api 매개 변수가 수신되면 jsone_encode을 수행하고 있습니다.Codeigniter : "set"메서드를 사용하여 항목을 업데이트해야합니다.

컨트롤러 :

public function send_request(){ 
      if($this->input->post('submit')){   
       $user_data['data'] = array( 
        'user_id'    => 1, 
        'sender_name'   =>  $this->input->post('sender_name'), 
        'sender_location'  =>  $this->input->post('sender_location'), 
        'sender_mobile'   =>  $this->input->post('sender_mobile'), 
        'receiver_name'   =>  $this->input->post('reciever_name'), 
        'receiver_location'  =>  $this->input->post('reciver_location'), 
        'receiver_mobile'  =>  $this->input->post('reciver_location'), 
        'request_type'   =>  $this->input->post('request_type'), 
        'is_urget'    =>  0, 
       ); 

      } 
      $result = $this->user_model->send_request($user_data); 
      if($result){ 
       $this->result_set['message'] = 'Data entered '; 
       $this->result_set['status']= 1; 
      } 
       if($this->input->post('is_api') == 1){ 
        echo json_encode($this->result_set); 
        die(); 
       } 
     } 

모델 : 내가 API에 대한 hurl.it 검사 할 때

public function send_request($data){ 
     $this->db->insert('parcel_requests',$data['data']); 
     return true; 
    } 

, 내가 얻을이 오류 및 응답 :

다음은 코드입니다

데이터베이스 오류가 발생했습니다.

항목을 업데이트하려면 "set"메서드를 사용해야합니다.

파일 이름 : /home/foldername/public_html/parcel/models/user_model.php

가 줄 번호가

: 줄 번호 (21) (21)

이된다

$this->db->insert('parcel_requests',$data['data']); 

지금 데이터를 입력 제대로 처리되었지만 은 json으로 변환되지 않았습니다.. 이 문제를 해결하는 데 도움이 필요합니다. 감사합니다.

+1

$data['data'] = array로는 가지고 당신은에 시도 단지 $ data 배열을 $ data [ 'data'] 대신 insert 함수에 전달하면됩니까? – Franco

+0

'$ sql = $ this-> db-> set ($ data [ 'data']) -> get_compiled_insert ('parcel_requests')로 쿼리 문자열을 확인하십시오; echo $ sql;' – BitAccesser

답변

0

확인이 :

이 예외를 보여줍니다 왜 :) 버전에서 빈 배열을 보낼 수 :) 그리고 그게 전부가 있었다
public function send_request(){ 
    if($this->input->post('submit')){ 
     $user_data['data'] = array(
      'user_id'    => 1, 
      'sender_name'   =>  $this->input->post('sender_name'), 
      'sender_location'  =>  $this->input->post('sender_location'), 
      'sender_mobile'   =>  $this->input->post('sender_mobile'), 
      'receiver_name'   =>  $this->input->post('reciever_name'), 
      'receiver_location'  =>  $this->input->post('reciver_location'), 
      'receiver_mobile'  =>  $this->input->post('reciver_location'), 
      'request_type'   =>  $this->input->post('request_type'), 
      'is_urget'    =>  0, 
     ); 
     // inside your if ;), you should insert to database only if you submit data... 

     $result = $this->user_model->send_request($user_data); 
     if($result){ 
      $this->result_set['message'] = 'Data entered '; 
      $this->result_set['status']= 1; 
     } 
     if($this->input->post('is_api') == 1){ 
      echo json_encode($this->result_set); 
      die(); 
     } 
    } else { 
     print 'nthg sumbited'; 
    } 
} 

public function send_request($data){ 
    $this->db->insert('parcel_requests',$data['data']); 
    return $this->db->affected_rows() == 1; 
    // Will return true after insert will be ended with success 
} 

0

변화 당신의 $user_data['data'] = array

관련 문제