简体   繁体   English

Codeigniter:您必须使用“set”方法来更新条目

[英]Codeigniter: You must use the “set” method to update an entry

I am trying to insert data using a submitted form.我正在尝试使用提交的表单插入数据。 Data is entered properly in the database, but I'm doing API also for mobile.数据在数据库中正确输入,但我也在为移动设备做 API。 If is_api parameter is received, I'm doing jsone_encode .如果收到is_api参数,我正在做jsone_encode The following is the code:以下是代码:

Controller:控制器:

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();
                }
         }

Model:型号:

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

When I check hurl.it for API, I get this error and response:当我检查hurl.it的 API 时,我收到此错误和响应:

A Database Error Occurred发生数据库错误

You must use the "set" method to update an entry.您必须使用“set”方法来更新条目。

Filename: /home/foldername/public_html/parcel/models/user_model.php文件名:/home/foldername/public_html/parcel/models/user_model.php

Line Number: 21行号:21

This is line number 21:这是第 21 行:

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

Now data is entered properly, but not converted to json .现在数据输入正确,但没有转换为 json I need your help to sort out this issue, thanks!我需要你的帮助来解决这个问题,谢谢!

Check this:检查这个:

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
}

In your version there was possibility to send empty array :) and thats why this exception shows :)在您的版本中,有可能发送空数组 :) 这就是为什么显示此异常的原因 :)

将您的$user_data['data'] = array更改$data['data'] = array

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Codeigniter您必须使用“设置”方法来更新条目5 - Codeigniter You must use the “set” method to update an entry 5 CodeIgniter DataMapper错误:您必须使用“set”方法来更新条目 - CodeIgniter DataMapper Error: You must use the “set” method to update an entry 错误:您必须使用“set”方法更新条目 - Error:You must use the “set” method to update an entry 错误:您必须使用“set”方法来更新条目修复? - Error: You must use the "set" method to update an entry fix? 发生数据库错误:您必须使用“set”方法来更新条目 - A Database Error Occurred: You must use the "set" method to update an entry CI4 您必须使用“设置”方法来更新条目。 已经用set了,还是报错 - CI4 You must use the "set" method to update an entry. Already use set, still error 您必须使用“set”方法来更新条目如何在 php codenniter 中纠正 - You must use the "set" method to update an entry how to rectify in php codengniter Codeigniter4 显示即使我使用了“set”方法,运行更新查询时也必须使用“set”方法 - Codeigniter4 shows You must use the "set" method when running update query even I used "set" method 必须使用设定方法 - Must use set method Codeigniter 不允许我更新条目,因为某些字段必须是唯一的 - Codeigniter doesn't let me update entry, because some fields must be unique
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM