亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法通過 rest api 插入數據

無法通過 rest api 插入數據

PHP
慕雪6442864 2022-12-23 13:27:22
我嘗試在 codeigniter 中使用 rest api 來插入數據。我試試這個    public function sensor_post(){    $data = array(                'sensor_id'   => $this->input->post('sensor_id'),                'value'       => $this->input->post('value'));    $insert = $this->db->insert('measurement', $data);    if ($insert) {        $this->response($data, 200);    } else {        $this->response(array('status' => 'fail', 502));    }  }并調用 http://localhost/rest_iot/index.php/iot/sensor?sensor_id=1&value=37我在郵遞員中嘗試這樣做,但出現這樣的錯誤。我想我已經填滿了價值,為什么會這樣?   <h1>A Database Error Occurred</h1>    <p>Error Number: 1048</p>    <p>Column 'sensor_id' cannot be null</p>    <p>INSERT INTO `measurement` (`sensor_id`, `value`) VALUES (NULL, NULL)</p>    <p>Filename: C:/xampp/htdocs/rest_iot/system/database/DB_driver.php</p>    <p>Line Number: 691</p>
查看完整描述

3 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

如果您在 URL 中發送數據,則您是通過 GET 發送數據。但是,您的代碼正在嘗試接收通過 POST 發送的數據。我假設在 codeigniter 中您可以簡單地編寫如下代碼以將其作為 GET 接收:


        'sensor_id'   => $this->input->get('sensor_id'),

        'value'       => $this->input->get('value')


查看完整回答
反對 回復 2022-12-23
?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

您是通過 GET 還是 POST 發送數據?假設$this->post('sensor_id')您正在尋找 POST 但通過 GET 發送sensor_id=1&value=37

通過 POST 方法發送數據或...通過 GET 檢索


查看完整回答
反對 回復 2022-12-23
?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

您在帖子字段中缺少輸入。


public function sensor_post()

    {

        $data = array(

            'sensor_id'   => $this->input->post('sensor_id'),

            'value'       => $this->input->post('value')

        );


        $insert = $this->db->insert('measurement', $data);


        if ($insert) {

            $this->response($data, 200);

        } else {

            $this->response(array('status' => 'fail', 502));

        }

    }

這對你有用。


查看完整回答
反對 回復 2022-12-23
  • 3 回答
  • 0 關注
  • 150 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號